From 04c9cc2c4f1826454aa955347da426862a36c0bd Mon Sep 17 00:00:00 2001 From: Martin Strecker <103252490+martin-strecker-sonarsource@users.noreply.github.com> Date: Mon, 27 Feb 2023 12:54:03 +0100 Subject: [PATCH] Modify rule S2970: Improve description of supported test library functions (#1518) --- rules/S2970/csharp/rule.adoc | 20 ++++++++++++++++++-- rules/S2970/description.adoc | 1 - 2 files changed, 18 insertions(+), 3 deletions(-) delete mode 100644 rules/S2970/description.adoc diff --git a/rules/S2970/csharp/rule.adoc b/rules/S2970/csharp/rule.adoc index 99dbde1b75d..59320137efd 100644 --- a/rules/S2970/csharp/rule.adoc +++ b/rules/S2970/csharp/rule.adoc @@ -1,11 +1,22 @@ -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 @@ -13,7 +24,12 @@ actual.Should(); // Noncompliant [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[] diff --git a/rules/S2970/description.adoc b/rules/S2970/description.adoc deleted file mode 100644 index 63e9c6f0174..00000000000 --- a/rules/S2970/description.adoc +++ /dev/null @@ -1 +0,0 @@ -It is very easy to write incomplete assertions when using some test frameworks. This rule raises an issue when an assertion doesn't actually test anything. \ No newline at end of file