This repository has been archived by the owner on Jun 12, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 46
Continuing on failure
Adam Ralph edited this page Aug 4, 2015
·
4 revisions
When any step in a scenario fails, the default behaviour of xBehave.net is to skip all remaining steps. However, there may be cases when you want to continue the execution of remaining steps when a specific step fails. This can be done very easily using the OnFailure()
extension method.
E.g. let us imagine that our calculator is some bizarre steampunk museum piece which tends to overheat. We may want to ensure that it doesn't overheat when adding two numbers together, but in the case it does, we are still interested in getting the right answer. If the calculator does overheat, the scenario will still fail, since that step will fail, but the step which test the answer will still be run so that we can inspect the outcome of the assertion.
[Scenario]
public void Addition(int x, int y, Calculator calculator, int answer)
{
"Given the number 1"
.f(() => x = 1);
"And the number 2"
.f(() => y = 2);
"And a calculator"
.f(() => calculator = new Calculator());
"When I add the numbers together"
.f(() => answer = calculator.Add(x, y));
"Then the calculator temperature should remain below 100 degrees"
.f(() => calculator.Temperature.Should().BeLessThan(100))
.OnFailure(RemainingSteps.Run);
"And the answer is 3"
.f(() => answer.Should().Be(3));
}