-
Notifications
You must be signed in to change notification settings - Fork 868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add FluentAssertions nuget package to test projects #8946
Conversation
I don't have a lot of personal experience with FluentAssertions. Are there any benefits you see of adopting it except for syntax differences, such as things xunit assertions cannot do easily, or better diagnostic messages? I'm leaning towards keeping one way of doing things unless there is enough merit where we can say the new approach is the new default. |
Thanks for your reply.
More readable diagnostic message.Basically FluentAssertions output more readable diagnostic message. For example. 1. FluentAssertions assertion var results = new[] { "Dummy" };
results.Should().HaveCount(0); Message:
2. xUnit.NET assertion var results = new[] { "Dummy" };
Assert.True(results.Length== 0); Message:
It can be confirmed FluentAssertions output contains more assertion context information. And FluentAssertions have Subject Identification feature. For Example Original code docfx/test/docfx.Tests/MetadataCommandTest.cs Line 356 in 2fc5c76
FluentAssertionsassertion > tocViewModel[2].Items[0].Uid.Should().Be("SubBar"); Message:
FluentAssertions features that can't do easily with xunit assertions.Below is an excerpt features that I want to use when writing unit tests. AssertionScopeThis feature is useful when writing following tests.
Example of Example of
Basically this type of test should be written using xUnit's Object Graph ComparisonThis feature is useful for POCO/DTO class (with no // Act
var actual = JsonUtility.Deserialize<BuildJsonConfig>("<path>")
// Assert
actual.Should().BeEquivalent(new BuildJsonConfig{
// Set properties to assert.
}); ExtensibilityIt can write custom assertion logics for specific types (e.g. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! I like object graph comparison and improved diagnostics.
Add FluentAssertions package to test projects
This PR add FluentAssertions NuGet package to test projects.
Background
Currently xUnit's assertions are used for unit tests.
I want to write unit test assertions with
FluentAssertions
assertion helpers. when adding new tests.FluentAssertions
is published asApache License 2.0
and widely used inorg:dotnet
repositoriesSo I thought there is no major obstacles to adapt this assertion library.
If these changes aren't accepted. feel free to close this PR.