Context managed by JBehave


Create a Context managed by JBehave:

  • The Context is managed only and only by JBehave. It is not directly accessible by the user of the framework.

  • The Context is cleared after the execution of every scenario (if the scenario is parametrised, it is cleared after the execution of every example).

  • The Context is handled properly when stories are executed concurrently.

  • The Context should favour immutability. For example, when possible, make stored collections immutable.

  • Input parameters:

    • A method implementing one step accepts as input parameters not only the ones taken from the step, but also parameters stored in the Context.

    • If an input parameter coming from the Context is null or does not exist when the method is invoked, an error is raised.

  • Output parameters:

    • If the method implementing one step returns a value, the framework stores this value into the Context.

    • If the returned value already exists in the Context, an error is raised.

    • If the returned value is a Collection, an immutable version of it (when possible) is stored in the Context.

As an example, the parameters can be identified by name using the value of an annotation.
The following step accepts a parameter from the step, 'fromStep', and also a parameter from the Context stored with the name 'inputName'.
The method also returns a String that is stored in the Context with the name 'outcomeName'.




Laura Ruiz Linde



Fix versions