Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify rule S2970: Improve description of supported test library functions #1518

Merged
merged 4 commits into from Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 23 additions & 2 deletions rules/S2970/csharp/rule.adoc
@@ -1,19 +1,40 @@
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:

* MSTest: https://learn.microsoft.com/dotnet/api/microsoft.visualstudio.testtools.unittesting.assert.that[`Assert.That`] is not followed by an assertion invocation (also https://learn.microsoft.com/dotnet/api/microsoft.visualstudio.testtools.unittesting.stringassert.that[`StringAssert.That`] and https://learn.microsoft.com/dotnet/api/microsoft.visualstudio.testtools.unittesting.collectionassert.that[`CollectionAssert.That`]).
* 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick comment: both this sentence and the next one lack the full stop at the end.

* 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
// MSTest
StringAssert.That; // Noncompliant
// Fluent Assertions
actual.Should(); // Noncompliant
// NFluent
Check.That(actual); // Noncompliant
// NSubstitute
command.Received(); // Noncompliant
----

== Compliant Solution

[source,csharp]
----
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();
----

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

This file was deleted.