Introduction
Library to convert BDD features into Python unittest.TestCase classes. Run the tests with your favorite test runner, like pytest, unittest or nose. See the demo folder for an example.
Example
Let’s take a calculator as an example. Create a plain text file called calculator.feature containing the BDD-style feature description:
Feature: Basic math operations
Test addition
Scenario: add
Given the value 10
When adding 7
Then the result is 17
Scenario: add a negative value
Given the value 19
When adding -11
Then the result is 8
This is the text you can discuss with the customer and agree on. Next write a backing file called test_calculator.py containing the code to run this feature:
import os
from bdd import Environment
from calculator import Calculator
env = Environment()
env.context.calculator = Calculator()
@env.given('the value {:d}')
def step(context, value):
context.calculator.value = value
@env.when('adding {:d}')
def step(context, value):
context.calculator.add(value)
@env.then('the result is {:d}')
def step(context, value):
assert context.calculator.value == value
def rel(p):
this_dir = os.path.dirname(os.path.abspath(__file__))
return os.path.join(this_dir, p)
CalculatorTestCase = env.load_feature_as_testcase('calculator.feature')
Finally, write the actual production code to implement the calculator, in a file called calculator.py:
class Calculator:
def __init__(self):
self.value = 0
def add(self, value):
self.value += value
Now run the tests with, for example, pytest:
$ python -m pytest test_calculator.py -v
=========== test session starts ===========================
platform linux -- Python 3.5.1, pytest-2.9.1
collected 2 items
test_calculator.py::CalculatorTestCase::test_scenario_0 <- bdd.py PASSED
test_calculator.py::CalculatorTestCase::test_scenario_1 <- bdd.py PASSED
References
A really good python bdd library is behave.
Changelog
0.2
Add tag support
0.1 (Jun 2, 2016)
Initial release
Release files for bdd 0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| bdd-0.2.zip | 4.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bdd-0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.1 kB
Release files / bdd-0.2.zip
| Download URL | bdd-0.2.zip |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3e038357e9046a67b65fc47bf9b94ca02f57a74e2d03429d31da0c77495b4a66
|
|
BLAKE2b-256 checksum How to use checksums |
d661deb6a361d811da8b6d9d9005123fc2cf859909a01603f573e0bc357d4a5e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / bdd-0.2-py3-none-any.whl
| Download URL | bdd-0.2-py3-none-any.whl |
|---|---|
| Size | 3.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f4ddac067e4632ce9e95b53ea7cfcff627194b536c61e91b1b5c9c7e0e81e3a0
|
|
BLAKE2b-256 checksum How to use checksums |
bf3b9093b494c9d4a11d8b57a569be35b604a4b987b029708ca6a0f40e7f818d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |