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. We have a page further describing this philosophy.
behave uses tests written in a natural language style, backed up by Python code.
Summary
To install this tool, you will need:
- Python library
- local
- from a Docker container
- pip (already installed if you are using Python 2 >=2.7.9 or Python 3 >=3.4))
Windows
Microsoft Visual C++ 14.0 (2015) with C++ Build Tools is required before installing pip
.
Note that while the error is calling for vc++ 14.0 - everything will work with newer versions of visual C++.
pip install behave
pip will install Behave in C:\Users\<username>\AppData\Local\Programs\Python\Python39\Scripts
.
See full documentation to integrate Behave into Jetbrains PyCharm IDE.
Configuration files for behave are called either .behaverc
, behave.ini
, setup.cfg
or tox.ini
(your preference) and are located in one of these places:
- the current working directory (good for per-project settings),
- your home directory ($HOME), or on Windows, in the %APPDATA% directory
If you are wondering where behave is getting its configuration defaults from you can use the -v
command-line argument.
Configuration files must start with the label [behave]
and are formatted in the Windows INI style, for example:
[behave]
format=plain
logging_clear_handlers=yes
logging_filter=-suds
You can now write your tests.
Example features/example.feature
:
Feature: Showing off behave
Scenario: Run a simple test
Given 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 tutorial.py
containing:
from behave import *
@given('we have behave installed')
def step_impl(context):
pass
@when('we implement a test')
def step_impl(context):
assert True is not False
@then('behave will test it for us!')
def step_impl(context):
assert context.failed is False
See the full tutorial on how to write complex tests.
Behave operates on directories containing:
feature files
(written by your Business Analyst / Sponsor / whoever with your behaviour scenarios in it)- a
steps
directory with Python step implementations for the scenarios.
You may optionally include some environmental controls (code to run before and after steps, scenarios, features or the whole shooting match).
The minimum requirement for a features directory is:
features/
features/everything.feature
features/steps/
features/steps/steps.py
A more complex directory might look like:
features/
features/signup.feature
features/login.feature
features/account_details.feature
features/environment.py
features/steps/
features/steps/website.py
features/steps/utils.py
If you’re having trouble setting things up and want to see what behave is doing in attempting to find your features use the -v
(verbose) command-line switch.
Softwares that Enhances behave
behave
You can generate Allure report for your Behave tests.
First you need to install Allure Behave formatter:
pip install allure-behave
Then specify the formatter when run your tests:
behave -f allure_behave.formatter:AllureFormatter -o %allure_result_folder% ./features
This will generate JSON report to %allure_result_folder%
.
Then, to view HTML report you can use Allure Command line:
allure serve %allure_result_folder%
For more details about Allure report you can see the documentation.