2023-05-03 11:06:20 +02:00
== Why is this an issue?
2024-02-28 16:24:40 +01:00
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.
2020-06-30 12:48:07 +02:00
2024-02-28 16:24:40 +01:00
=== Exceptions
2020-06-30 12:48:07 +02:00
2024-02-28 16:24:40 +01:00
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()`.
2021-06-02 20:44:38 +02:00
2024-02-28 16:24:40 +01:00
include::how-mstest.adoc[]
2021-09-20 15:38:42 +02:00
2024-02-28 16:24:40 +01:00
include::how-nunit.adoc[]
2021-09-20 15:38:42 +02:00
2024-02-28 16:24:40 +01:00
include::how-xunit.adoc[]
2021-09-20 15:38:42 +02:00
2024-02-28 16:24:40 +01:00
== Resources
2021-06-02 20:44:38 +02:00
2024-02-28 16:24:40 +01:00
=== Documentation
2023-06-22 10:38:01 +02:00
2024-02-28 16:24:40 +01:00
* 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[]