Hallo Welt
foo
Bar
- one
- two
In addition to the fully supported Gherkin language radish supports some more functionality like: Scenario Preconditions, Scenario Loops, Variables and Expressions.
radish tries to provide the most awesome pythonic experiences when implementing your steps and hooks. Your test code should be as great as your project's code.
radish is available in PyPi. Use pip to install radish:
pip install radish-bdd
All your tests are written in the BDD gherkin language and saved as .feature files.
Let's name ours calculator.feature. A feature file is as simple as the following:
Feature: My first feature file using radish
In order to test my awesome software
I need an awesome BDD tool like radish
to test my software.
Scenario: Test my calculator
Given I have the numbers 5 and 6
When I sum them
Then I expect the result to be 11
Every line inside a Scenario is called a step. You have to provide a python function for every step in order to execute some code. Let's create a new "radish" directory and write our first step.py file there:
# -*- coding: utf-8 -*-
from radish import given, when, then
@given("I have the numbers {number1:g} and {number2:g}")
def have_numbers(step, number1, number2):
step.context.number1 = number1
step.context.number2 = number2
@when("I sum them")
def sum_numbers(step):
step.context.result = step.context.number1 + \
step.context.number2
@then("I expect the result to be {result:g}")
def expect_result(step, result):
assert step.context.result == result
Nothing more is needed - Let's run our tests:
radish calculator.feature