Assert.True or Assert.IsTrue is given an equality comparison, which hides both values when it fails

tx0/csharp:boolean-assert-of-comparisonallwarningmaintainability/testsdepth faststyle

What it finds

Assert.True(a == b) fails with "expected true, got false". Assert.Equal(b, a) fails with both values, which is what one needs to find the bug.

From the rule's source, boolean_assert_of_comparison.rs.

Example from the rule's tests
using Xunit; public class Totals{    [Fact]    public void Sums()    {        int total = 4;        Assert.True(total == 4);tx0 reports: a comparison is asserted as a boolean, which hides both values on failure        Assert.True(total > 0);    }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the all tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/csharp:boolean-assert-of-comparison" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/csharp:boolean-assert-of-comparison] reason="..."

tx0 explain tx0/csharp:boolean-assert-of-comparison shows the same in the terminal. Found a false positive? Report it.