Skip to content
davidmfoley edited this page Sep 13, 2010 · 5 revisions

There are three lifetimes or “scopes” that exist during a StorEvil run.

The lifetime of a context class can be set by using the “Lifetime” parameter on the Context Attribute.


[StorEvil.Context(Lifetime=StorEvil.ContextLifetime.Scenario)]
public class ExampleContextThatLivesForOneScenario { }

There are three possible settings for lifetime:

Scenario (default)

A new instance of the context class will be created for each scenario. Within a scenario, the same instance will be used. For scenario outlines, a new instance is created for each example.

Story

A new instance of the context class will be created for each story (plaintext specification/feature file). Within a story, the same instance will be reused in each scenario.

Session

A single instance of the context class will be created for the entire run. This is intended for use with, for example, setting up a Selenium or WATiN session, or initializing a database to a known state.

Notes about Lifetimes in dependent classes

Contexts that depend on other contexts (as constructor parameters) cannot depend on contexts that have a shorter lifetime.
If a context class depends on another that has a shorter lifetime, a ConflictingLifetimeException will be thrown.

See Dependent Contexts for more information about contexts that depend on other contexts.