Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vchrombie/bdd-testing-behave
behaviour driven development testing with python and behave demo
https://github.com/vchrombie/bdd-testing-behave
bdd-tests behave behavior-driven-development
Last synced: 12 days ago
JSON representation
behaviour driven development testing with python and behave demo
- Host: GitHub
- URL: https://github.com/vchrombie/bdd-testing-behave
- Owner: vchrombie
- Created: 2022-03-01T19:13:30.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-03-01T20:30:04.000Z (almost 3 years ago)
- Last Synced: 2024-11-05T07:40:35.930Z (about 2 months ago)
- Topics: bdd-tests, behave, behavior-driven-development
- Language: Python
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# bdd-testing-behave
## Installation
```
$ poetry add behave
```## Structure
```
.
|____calculator.py
|____features
| |____steps
| | |____steps.py
| |____calculator.feature
| |____environment.py
```- `calculator.py` contains the source code the calculator app
- `features/` contains all the files related to `behave` (feature configurations, steps, etc.)
- `features/calculator.feature` contains the feature configurations for the calculator (features, scenarios, rules, etc.)
- `features/environment.py` used to define code to run before and after certain events
- `features/steps/` contains the steps implementations
- `features/steps/steps.py` contains the steps for calculator## Example
### tests pass
```
(.venv) $ behave
Feature: Test Calculator Functionality # features/calculator.feature:2Scenario: Addition # features/calculator.feature:4
Given I have the numbers 10 and 5 # features/steps/steps.py:4 0.001s
When I add them # features/steps/steps.py:11 0.000s
Then I expect the result to be 15 # features/steps/steps.py:21 0.000sScenario: Subtraction # features/calculator.feature:9
Given I have the numbers 10 and 5 # features/steps/steps.py:4 0.000s
When I sub them # features/steps/steps.py:11 0.000s
Then I expect the result to be 5 # features/steps/steps.py:21 0.000sScenario: Multiplication # features/calculator.feature:14
Given I have the numbers 10 and 5 # features/steps/steps.py:4 0.000s
When I mult them # features/steps/steps.py:11 0.000s
Then I expect the result to be 50 # features/steps/steps.py:21 0.000sScenario: Division # features/calculator.feature:19
Given I have the numbers 10 and 5 # features/steps/steps.py:4 0.000s
When I div them # features/steps/steps.py:11 0.000s
Then I expect the result to be 2 # features/steps/steps.py:21 0.000s1 feature passed, 0 failed, 0 skipped
4 scenarios passed, 0 failed, 0 skipped
12 steps passed, 0 failed, 0 skipped, 0 undefined
Took 0m0.003s
```### tests fail
```
(.venv) $ behave
Feature: Test Calculator Functionality # features/calculator.feature:2. . .
Scenario: Modulus # features/calculator.feature:24
Given I have the numbers 10 and 5 # features/steps/steps.py:4 0.000s
When I mod them # features/steps/steps.py:11 0.000s
Then I expect the result to be 1 # features/steps/steps.py:21 0.000s
Assertion Failed: Expected 1, got 0
Captured stdout:
STEP: Given I have the numbers 10 and 5
STEP: When I add them
STEP: Then I expect the result to be 1Failing scenarios:
features/calculator.feature:24 Modulus0 features passed, 1 failed, 0 skipped
4 scenarios passed, 1 failed, 0 skipped
14 steps passed, 1 failed, 0 skipped, 0 undefined
Took 0m0.002s
```## Resources
- https://behave.readthedocs.io/en/stable/tutorial.html
- https://medium.com/@hmurari/bdd-quickstart-with-python-4cf366cfc11c