-
Notifications
You must be signed in to change notification settings - Fork 0
Can I use xWellBehaved.net with fluent assertion libraries
Of course!
You can use any fluent assertion library you like with xBehave.net.
The xBehave.net recommendation is FluentAssertions.
using FluentAssertions;
public class CalculatorFeature
{
[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.Add(x, y));
"Then the answer is 3".x(() => answer.Should().Be(3));
}
}
We here with xWellBehaved.net are partial to our own xunit.fluently.assert and related packages, since, after all, we wrote them!
public class CalculatorFeature
{
using Xunit;
[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));
// String together fluent assertions such as these: ^^^^^^^^^^^^^^^
"Then the answer is 3".x(() => answer.AssertTrue(x => x > 0).AssertEquals(3));
// And more fluent chaining: ^^^^^^^^^^^^^^^^^^^^^^.^^^^^^^^^^^^^^^
}
}
Shameless plug, We think the added benefit of our approach is that we do not beat around any bushes with fluent syntax, we get in, make an assertion, and get out, while also affording an opportunity for you to return the subject under test for subsequent fluent usage. With a few exceptions, assertions involving object
, for instance, this is predominantly the case. Of course, the examples above are all a bit contrived, and are there illustration only.
However, again, you are free to run with what you know.
- 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