-
Notifications
You must be signed in to change notification settings - Fork 0
Continuing on failure
When any step in a scenario fails, the default behaviour of xWellBehaved.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.
For instance, let us imagine that our calculator is some bizarre steampunk museum piece which tends to overheat. We may want to ensure that it does not 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 the step that tests the temperature will fail, but the subsequent step which tests the answer will still be run so that we can still inspect the outcome of that assertion.
[Scenario]
public void Addition(int x, int y, Calculator calculator, int answer)
{
"Given the number 1".x(() => x = 1);
"And the number 2".x(() => y = 2);
"And a calculator".x(() => calculator = new Calculator());
"When I add the numbers together".x(() => answer = calculator.AssertNotNUll().Add(x, y));
"Then the calculator temperature should remain below 100 degrees"
.x(() => calculator.AssertTrue(x => x.Temperature < 100))
.OnFailure(RemainingSteps.Run);
// ^^^^^^^^^^^^^^^^^^
"And the answer is 3".x(() => answer.AssertEqual(3));
}
- Home
- Quick start
-
Documentation
- Writing scenarios
- Running scenarios
- Package dependencies
- Debugging scenarios
- Assertions
- Step names
- Debugging Scenarios with examples
- Background methods
- TearDown methods
- Async steps
- Object disposal
- Rollback
- Skipping steps and scenarios
- Step metadata
- Continuing on failure
- Step filters
- Changes in xBehave.net version 2.0
- Changes since deriving from xBehave.net
- Extending xWellBehaved.net
- FAQ
- Known Issues
- Contributions