Skip to content

Instantly share code, notes, and snippets.

@GraemeBradbury
Created April 2, 2015 12:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GraemeBradbury/c14eb5133bb01f979328 to your computer and use it in GitHub Desktop.
Save GraemeBradbury/c14eb5133bb01f979328 to your computer and use it in GitHub Desktop.
Multiple asserts single detailed response
That's not really a pattern and more a tooling thing.
Sometimes scenarios have behaviour that has multiple aspects, which individually are worthless but together have worth.
So contrived scenario ahead
Given a Spline
When it's Retriculated
Then it beeps
And it flashes
For a business user this is a good scenario since "working" means both beeping and flashing.
However from the dev point of view this is irritating since test runner will stop at the first failure, which makes it harder to identify if the behaviour was broken at the Spline code, the sound code or at the light code.
So in an ideal world a test runner would be able to show:
Given a Spline
When it's Retriculated
Then it beeps <-- Failed!
And it flashes <-- Passed!
@NathanGloyn
Copy link

Pseudo code but you'll get the idea, I was more thinking:

void FixtureSetup(){
result = target.Execute();
}

[Test]
void test1(){
Assert.That(result.one, Is.EqualTo("one");
}

[Test]
void test2() {
Assert.That(result.two, Is.EqualTo("two")
}

@adamralph
Copy link

A possible enhancement to xbehave is the ability to specify that the failure of a certain step does not prevent execution of subsequent steps

E.g.

"Given a Spline"
    .f(() => ...);

"When it's Retriculated"
    .f(() => ...);

"Then it beeps"
    .f(() => ...)
    .ContinueOnFailure();

"And it flashes"
    .f(() => ...);

@adamralph
Copy link

In xbehave 1.1, you can fudge this using backgrounds, e.g.

[Background]
public void Background()
{
    "Given a Spline"
        .f(() => ...);

    "When it's Retriculated"
        .f(() => ...);
}

[Scenario]
public void Beeping()
{
    "Then it beeps"
        .f(() => ...);
}

[Scenario]
public void Flashing()
{
    "Then it flashes"
        .f(() => ...);
}

But the test output won't really convey the right semantics.

@adamralph
Copy link

Breaking news: ContinueOnFailure is coming in 2.0 - https://github.com/xbehave/xbehave.net/wiki/Changes-in-version-2.0

@adamralph
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment