site/xunit.analyzers/rules/xUnit2009.md
A violation of this rule occurs when Assert.True or Assert.False are used to check for substrings with string methods like string.Contains, string.StartsWith and string.EndsWith.
There are specialized assertions for substring checks.
To fix a violation of this rule, replace the offending assertion according to this:
Assert.True(str.Contains(word)) => Assert.Contains(word, str)Assert.False(str.Contains(word)) => Assert.DoesNotContain(word, str)Assert.True(str.StartsWith(word)) => Assert.StartsWith(word, str)Assert.True(str.EndsWith(word)) => Assert.EndsWith(word, str)using Xunit;
public class xUnit2009
{
[Fact]
public void TestMethod()
{
var result = "foo bar baz";
Assert.True(result.Contains("bar"));
}
}
using Xunit;
public class xUnit2009
{
[Fact]
public void TestMethod()
{
var result = "foo bar baz";
Assert.Contains("bar", result);
}
}