Skip to content

behaviour driven development testing with python and behave demo

Notifications You must be signed in to change notification settings

vchrombie/bdd-testing-behave

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

behaviour driven development testing with python and behave demo

Topics

Resources

Stars

Watchers

Forks