Why is this an issue?
It is very easy to write incomplete assertions when using some test frameworks. This rule enforces complete assertions in the following cases:
- 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.
Noncompliant code example
string actual = "Hello World!";
// Fluent Assertions
actual.Should(); // Noncompliant
// NFluent
Check.That(actual); // Noncompliant
// NSubstitute
command.Received(); // Noncompliant
Compliant solution
string actual = "Hello World!";
// Fluent Assertions
actual.Should().Contain("Hello");
// NFluent
Check.That(actual).Contains("Hello");
// NSubstitute
command.Received().Execute();