Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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:2

Scenario: 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.000s

Scenario: 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.000s

Scenario: 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.000s

Scenario: 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.000s

1 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 1

Failing scenarios:
features/calculator.feature:24 Modulus

0 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