Introduction

Read the Documentation

Before you start reading this manual, you should have read the behave documentation to understand how behave works.

Hint

The cucumber and jbehave documentation might also be interesting for you, if you like to know where certain concepts originate.

Given, When, Then

You should understand the BDD concepts.

Feature: Title (one line describing the story/feature)

    As a    [role]
    I want  [feature]
    So that [benefit]

    Scenario: Title1 (for Behaviour 1)

        Given [context or setup]
        And  [some more context]...
        When [event occurs]
        Then [expected outcome]
        And  [another outcome]...

    Scenario: Title2 (for Behaviour 2)
        ...

Select an Assertion Matcher Library

Before you start to use behave (or any other BDD framework) you should select an assertion matcher library that you want to use in your project.

Python has a growing number of assertion matcher libraries by now. Here is the list of some of these:

Matcher Library Description
Native assert Starting point, but not enough information when assert fails.
hamcrest First assertion matcher library, now part of JUnit4. Supports several programming languages: github:/hamcrest/PyHamcrest
behave-pytest Enables pytest assertions in behave: (old repo: github:/ribozz/behave-pytest currently not usable)
nose.tools Part of the nose test framework
should_dsl An interesting small matcher library, https://pypi.org/project/should_dsl
sure Provided by the maker of lettuce, github:/gabrielfalcao/sure
compare https://pypi.org/project/compare
describe https://pypi.org/project/describe

Note

hamcrest is used as assertion matcher library in the examples presented here.