This rule addresses the issue of incomplete assertions that can occur when using certain test frameworks. Incomplete assertions can lead to tests that do not effectively verify anything. The rule enforces the use of complete assertions in specific cases, namely:
string actual = "Using Fluent Assertions"; actual.Should(); // Noncompliant
string actual = "Using NFluent"; Check.That(actual); // Noncompliant
command.Received(); // Noncompliant
In such cases, what is intended to be a test doesn’t actually verify anything.
Fluent Assertions provides an interface for writing assertions, and it is important to ensure that Should() is properly
used in conjunction with an assertion method.
string actual = "Hello World!"; actual.Should(); // Noncompliant
string actual = "Hello World!";
actual.Should().Contain("Hello");
NFluent offers a syntax for assertions, and it’s important to follow Check.That() with an assertion method to complete
the assertion.
string actual = "Hello World!"; Check.That(actual); // Noncompliant
string actual = "Hello World!";
Check.That(actual).Contains("Hello");
NSubstitute is a mocking framework, and Received() is used to verify that a specific method has been called. However,
invoking a method on the mock after calling Received() is necessary to ensure the complete assertion.
command.Received(); // Noncompliant
command.Received().Execute();