You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
behave is behavior-driven development, Python style.
Behavior-driven development (or BDD) is an agile software development
technique that encourages collaboration between developers, QA and
non-technical or business participants in a software project.
behave uses tests written in a natural language style, backed up by Python
code.
Now make a directory called "features/".
In that directory create a file called "example.feature" containing:
# -- FILE: features/example.featureFeature: Showing off behaveScenario: Run a simple testGiven we have behave installed
When we implement 5 tests
Then behave will test them for us!
Make a new directory called "features/steps/".
In that directory create a file called "example_steps.py" containing:
# -- FILE: features/steps/example_steps.pyfrombehaveimportgiven, when, then, step@given('we have behave installed')defstep_impl(context):
pass@when('we implement {number:d} tests')defstep_impl(context, number): # -- NOTE: number is converted into integerassertnumber>1ornumber==0context.tests_count=number@then('behave will test them for us!')defstep_impl(context):
assertcontext.failedisFalseassertcontext.tests_count>=0
Run behave:
$ behaveFeature: Showing off behave # features/example.feature:2 Scenario: Run a simple test # features/example.feature:4 Given we have behave installed # features/steps/example_steps.py:4 When we implement 5 tests # features/steps/example_steps.py:8 Then behave will test them for us! # features/steps/example_steps.py:131 feature passed, 0 failed, 0 skipped1 scenario passed, 0 failed, 0 skipped3 steps passed, 0 failed, 0 skipped, 0 undefined
Now, continue reading to learn how to get the most out of behave. To get started,
we recommend the tutorial and then the feature testing language and
api references.