Do not use boolean check to match on regular expressions
A violation of this rule occurs when Assert.True
or Assert.False
are used to check for regular expression matches.
There are specialized assertions for regular expression matching that give more detailed information upon failure.
Replace the assertions with Assert.Matches
or Assert.DoesNotMatch
.
using System.Text.RegularExpressions;
using Xunit;
public class xUnit2008
{
[Fact]
public void TestMethod()
{
var result = "foo bar baz";
Assert.True(Regex.IsMatch(result, "foo (.*?) baz"));
}
}
using Xunit;
public class xUnit2008
{
[Fact]
public void TestMethod()
{
var result = "foo bar baz";
Assert.Matches("foo (.*?) baz", result);
}
}