Skip to content

StorEvil Context Classes

davidmfoley edited this page Sep 13, 2010 · 12 revisions

StorEvil instantiates classes that you create (Context Classes) in order to interpret specifications.
These Context classes are similar to Steps in Cucumber.

Your context classes must follow a few rules:

  1. Must be public
  2. You must tell StorEvil the assemblies that contain your context classes using the storevil.config or a command-line switch.

for example:


public class ExampleContext  {
    public void Given_some_precondition() {
    }
}

Note that the types of any return values of context method for partial matches do not necessarily need to be public:


public class ExampleContext  {
    public ExampleSubContext Given_some_precondition() {
        return new ExampleSubContext();
    }
}

internal class ExampleSubContext {
   ...
}

Lifespan of context classes

A context class will be reused only during the interpretation of one scenario.
(Or one example in the case of a scenario outline).

IDisposable

If you need to clean up some resources at the end of a scenario, just implement IDisposable in your context class.

Dependencies between context classes.

StorEvil will do simple constructor injection of dependent contexts.

What this means is that any parameters to the constructor that you create will be shared between any classes that have them.
You can have one context that depends on another, or share a context class that is not used to parse grammar between contexts:


public class Foo {
    public Foo(Bar bar) {
        _bar = bar;
    }
}

public class Bar {
}

public class Baz {
    public Baz(Bar bar) {
        _bar = bar; // will get the same instance as Foo._bar
    }
}
Clone this wiki locally