TestCenter Reference
TestSupport.BDD Namespace Reference

Classes

class  _BDDContext
 

Functions

 Given ()
 
 GivenClause (func)
 
 WhenClause (func)
 
 ThenClause (func)
 
 _BDDClause (clauseType)
 

Detailed Description

Tools for writing human readable, behavioral tests.

The functions, decorators and classes defined in this module enable
you to write tests describing the desired behavior of a MeVisLab
module (or any other Python object).

A typical behavioral test looks like this:

def TEST_a_behavioral_test():
    Given().a_precondition(). \
    When().you_do_something(). \
    Then().something_happens()

i.e. it is the concatenation of several function calls, or, in other words,
it is a sentence consisting of a Given clause, a When clause, and a Then
clause.

Given(), When(), and Then() are predefined functions marking the start of
the Given clause (and of the whole sentence), the When clause, and the Then
clause, respectively.

There is another predefined function, And(), which can be used to concatenate
several custom functions of the same type, e.g.

    Given().precondition1(). \
    And().precondition2(). \
    [...]

The other functions are custom functions that are defined with the help
of three decorators: GivenClause, WhenClause, and ThenClause. (The decorators
add the decorated functions to the context class so that they can be called
as member functions.)

The Given() function creates and returns a context object for the test. All
other functions are member functions of this context object. These functions
also return the context object. This allows arbitrary chaining of those
functions. By adding attributes to the context object we can pass arbitrary
state from one function to the next.

See ExampleBDDTestCase in MeVisLab/Examples for an example.

For more information on Behavior Driven Development (BDD) check the Internet.

If you need a more powerful BDD-style language then have a look at one of the
existing Python BDD modules like behave, freshen, lettuce, etc.

Function Documentation

◆ _BDDClause()

TestSupport.BDD._BDDClause ( clauseType)
protected
Internal decorator used for defining clauses of different types.

Definition at line 177 of file BDD.py.

Referenced by TestSupport.BDD.GivenClause(), TestSupport.BDD.ThenClause(), and TestSupport.BDD.WhenClause().

◆ Given()

TestSupport.BDD.Given ( )
Initiates a sentence describing a desired behavior.

Creates and returns the context object for the test.

Definition at line 63 of file BDD.py.

◆ GivenClause()

TestSupport.BDD.GivenClause ( func)
Decorator for defining a Given clause.

The first argument that is passed to the decorated function is the
context object. Custom parameters are passed to the decorated
function after the context object.

The decorated function always returns the context object.

Example:
@GivenClause
def a_precondition(testContext):
    # perform the setup of the test, e.g. by parameterizing a TestPattern
    # module

Definition at line 70 of file BDD.py.

References TestSupport.BDD._BDDClause().

◆ ThenClause()

TestSupport.BDD.ThenClause ( func)
Decorator for defining a Then clause.

The first argument that is passed to the decorated function is the
context of the test case. Custom parameters are passed to the decorated
function after the context.

The decorated function always returns the context object.

Example:
@ThenClause
def something_happens(testContext):
    # check for the expected behavior, e.g. by comparing a field value
    # with an expected value

Definition at line 103 of file BDD.py.

References TestSupport.BDD._BDDClause().

◆ WhenClause()

TestSupport.BDD.WhenClause ( func)
Decorator for defining a When clause.

The first argument that is passed to the decorated function is the
context of the test case. Custom parameters are passed to the decorated
function after the context.

The decorated function always returns the context object.

Example:
@WhenClause
def you_do_something(testContext):
    # do whatever shall result in a certain behavior, e.g. touch a field

Definition at line 87 of file BDD.py.

References TestSupport.BDD._BDDClause().