site/xunit.analyzers/rules/xUnit2025.md
Boolean assertions which compare with equality against true or false can be simplified.
Simplifying an expression like Assert.True(x == true) to just Assert.True(x) makes the code simpler. Additionally,
inversions like Assert.True(x == false) are much easier to read and understand as Assert.False(x).
To fix a violation of this rule, remove the equality test (and update the assertion method, if necessary).
using Xunit;
public class xUnit2025
{
[Fact]
public void TestMethod()
{
var x = true;
Assert.True(x == true);
}
}
using Xunit;
public class xUnit2025
{
[Fact]
public void TestMethod()
{
var x = false;
Assert.True(x != true);
}
}
using Xunit;
public class xUnit2025
{
[Fact]
public void TestMethod()
{
var x = true;
Assert.True(x);
}
}
using Xunit;
public class xUnit2025
{
[Fact]
public void TestMethod()
{
var x = false;
Assert.False(x);
}
}