Skip to content

Commit

Permalink
Modify rule S2970: Improve description of supported test library func…
Browse files Browse the repository at this point in the history
…tions (#1518)
  • Loading branch information
martin-strecker-sonarsource committed Feb 27, 2023
1 parent 9ee31b9 commit 04c9cc2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
20 changes: 18 additions & 2 deletions rules/S2970/csharp/rule.adoc
@@ -1,19 +1,35 @@
include::../description.adoc[]
It is very easy to write incomplete assertions when using some test frameworks. This rule enforces complete assertions in the following cases:

* Fluent Assertions: https://fluentassertions.com/introduction[`Should()`] is not followed by an assertion invocation.
* NFluent: https://www.n-fluent.net[`Check.That()`] is not followed by an assertion invocation.
* NSubstitute: https://nsubstitute.github.io/help/received-calls[`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

[source,csharp]
----
string actual = "Hello World!";
actual.Should(); // Noncompliant
// Fluent Assertions
actual.Should(); // Noncompliant
// NFluent
Check.That(actual); // Noncompliant
// NSubstitute
command.Received(); // Noncompliant
----

== Compliant Solution

[source,csharp]
----
string actual = "Hello World!";
// Fluent Assertions
actual.Should().Contain("Hello");
// NFluent
Check.That(actual).Contains("Hello");
// NSubstitute
command.Received().Execute();
----

ifdef::env-github,rspecator-view[]
Expand Down
1 change: 0 additions & 1 deletion rules/S2970/description.adoc

This file was deleted.

0 comments on commit 04c9cc2

Please sign in to comment.