-
Notifications
You must be signed in to change notification settings - Fork 9
Context Lifetimes
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:
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.
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.
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.
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.