-
Notifications
You must be signed in to change notification settings - Fork 222
/
S2970_c#.html
29 lines (28 loc) · 1.12 KB
/
S2970_c#.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<p>It is very easy to write incomplete assertions when using some test frameworks. This rule enforces complete assertions in the following cases:</p>
<ul>
<li> Fluent Assertions: <a href="https://fluentassertions.com/introduction"><code>Should()</code></a> is not followed by an assertion invocation.
</li>
<li> NFluent: <a href="https://www.n-fluent.net"><code>Check.That()</code></a> is not followed by an assertion invocation. </li>
<li> NSubstitute: <a href="https://nsubstitute.github.io/help/received-calls"><code>Received()</code></a> is not followed by an invocation. </li>
</ul>
<p>In such cases, what is intended to be a test doesn’t actually verify anything.</p>
<h2>Noncompliant Code Example</h2>
<pre>
string actual = "Hello World!";
// Fluent Assertions
actual.Should(); // Noncompliant
// NFluent
Check.That(actual); // Noncompliant
// NSubstitute
command.Received(); // Noncompliant
</pre>
<h2>Compliant Solution</h2>
<pre>
string actual = "Hello World!";
// Fluent Assertions
actual.Should().Contain("Hello");
// NFluent
Check.That(actual).Contains("Hello");
// NSubstitute
command.Received().Execute();
</pre>