Storyteller 4.1.0


Carrying out Actions



Sentences Edit on GitHub

The simplest and most commonly used type of Grammar is just a single line within a Specification called a Sentence.

A Sample Specification Using Sentences

Again visiting the problem domain of writing our own Calculator software, we could use Sentence grammars to specify the multiplication and addition features like so:

Using Fixture Methods

The simplest way to write a Sentence grammar is to just add a public method to a Fixture class that either returns a single value or has a void signature.

The "Starts with " sentence used in the specification above looks like:

[FormatAs("Start with {value}")]
public void StartWith(double value)
    _calculator.Value = value;

The [FormatAs] attribute value specifies how the Sentence grammar will be rendered into HTML output. The syntax is to replace {parameter name} with the value of that method parameter in the HTML display. If you leave off the [FormatAs] attribute, Storyteller will just use the method signature as the format. In the case above, that format would be StartsWith({number}).

Asserting Values with the Return Value

There is some value in writing smoke tests just to see if the system blows up when you perform actions, but sooner or later you probably want to check some state or value returned from the system. You can use a Sentence method to assert on a single value like the TheValueShouldBe grammar used in the sample Specification above:

[FormatAs("The value should be {value}")]
public double TheValueShouldBe()
    return _calculator.Value;

If the expected value does not match the returned value from the grammar method, the results output will look like this:

Using Output Parameters

New in Storyteller 3.0 is the ability to use output parameters to specify multiple value assertions in a single Sentence method. Below is an example:

[FormatAs("Adding {x} to {y} should equal {returnValue}")]
public double AddingNumbersTogether(double x, double y)
    _calculator.Value = x;
    return _calculator.Value;

Used in a specification, that grammar would look like this:

See also: