-
Notifications
You must be signed in to change notification settings - Fork 0
Debugging Scenarios with examples
Michael W. Powell edited this page Jun 20, 2024
·
7 revisions
xWellBehaved.net allows the passing of example values for the parameters in a scenario method.
This is equivalent to Cucumber Scenario Outlines and works in a similar manner to xUnit.net [Theory]
attribute for data driven testing.
[Scenario
, Example(1, 2, 3)
, Example(2, 3, 5)]
public void Addition(int x, int y, int expected, int actual, Calculator calculator)
{
$"Given a number {x}".x(() => { });
$"Given a number {y}".x(() => { });
$"Given an expected result {expected}".x(() => { });
"And given calculator".x(() => calculator = new Calculator());
"When x plus y".x(() => actual = calculator.AssertNotNull().Add(x, y));
"Then actual equal to expected".x(() => actual.AssertEqual(expected));
}
YMMV; all scenarios are committed to source and may be verified independently, including output to show for it. We ran the following command from the output directory:
dotnet ..\..\..\..\packages\xunit.runner.console\2.4.1\tools\netcoreapp2.0\xunit.console.dll Test.Xwellbehaved.Samples.dll -class "Xwellbehaved.DebuggingScenariosWithExamples" -verbose -html Test.Xwellbehaved.Samples.dll.WithExamples.html
Results in this output:
There are few things to note here:
- Each parameter which does not have a corresponding example value, based purely on number of values/parameters, continues to have its default value passed;
null
for reference types and zero values for value types. - You are not limited to using only the
[Example]
attribute for providing values. Any attribute which derives from the xUnit.netDataAttribute
will also work, including xUnit.net's own[ClassData]
and[MemberData]
. - Each
[Example]
decoration effectively generates a new scenario.
- 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