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: http://code.google.com/p/hamcrest/
nose.tools Part of the nose test framework
should-dsl An interesting small matcher library, http://www.should-dsl.info/
sure Provided by the maker of lettuce, github:/gabrielfalcao/sure
compare http://pypi.python.org/pypi/compare
describe http://pypi.python.org/pypi/describe

Note

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