26 lines
1.2 KiB
Plaintext
26 lines
1.2 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Using literal boolean values in assertions can lead to less readable and less informative unit tests.
|
|
When a test fails, it's important to have a clear understanding of what the test was checking and why it failed.
|
|
Most of the testing frameworks provide more explicit assertion methods that will provide a more helpful error message if the test fails.
|
|
|
|
=== Exceptions
|
|
|
|
In the context of xUnit, `Assert.True` and `Assert.False` are not flagged by this rule. This is because `Assert.Fail` was only introduced in 2020 with version `2.4.2`. Prior to this, developers used `Assert.True(false, message)` and `Assert.False(true, message)` as workarounds to simulate the functionality of `Assert.Fail()`.
|
|
|
|
include::how-mstest.adoc[]
|
|
|
|
include::how-nunit.adoc[]
|
|
|
|
include::how-xunit.adoc[]
|
|
|
|
== Resources
|
|
|
|
=== Documentation
|
|
|
|
* https://docs.nunit.org/[NUnit Documentation]
|
|
* https://xunit.net/docs/getting-started/netcore/cmdline[xUnit Documentation]
|
|
* Microsoft Learn - https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-mstest[MSTest Documentation]
|
|
* https://github.com/xunit/xunit/issues/2027[Xunit doesn't have an Assert.Fail() operation]
|
|
|
|
include::../rspecator.adoc[] |