It is very easy to write incomplete assertions when using some test frameworks. This rule enforces complete assertions in the following cases:
-
MSTest:
Assert.That
is not followed by an assertion invocation (alsoStringAssert.That
andCollectionAssert.That
). -
Fluent Assertions:
Should()
is not followed by an assertion invocation. -
NFluent:
Check.That()
is not followed by an assertion invocation -
NSubstitute:
Received()
is not followed by an invocation
In such cases, what is intended to be a test doesn’t actually verify anything.
string actual = "Hello World!";
// MSTest
StringAssert.That; // Noncompliant
// Fluent Assertions
actual.Should(); // Noncompliant
// NFluent
Check.That(actual); // Noncompliant
// NSubstitute
command.Received(); // Noncompliant
string actual = "Hello World!";
// MSTest
StringAssert.That.Contains(actual, "Hello");
// Fluent Assertions
actual.Should().Contain("Hello");
// NFluent
Check.That(actual).Contains("Hello");
// NSubstitute
command.Received().Execute();
(visible only on this page)