
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
75 lines
1.2 KiB
Plaintext
75 lines
1.2 KiB
Plaintext
== Why is this an issue?
|
|
|
|
A common good practice is to write test methods targeting only one logical concept, that can only fail for one reason.
|
|
|
|
While it might make sense to have more than one assertion to test one concept, having too many is a sign that a test became too complex and should be refactored to multiples ones.
|
|
|
|
|
|
This rule will report any test method containing more than a given number of assertion.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
With a parameter of 2.
|
|
|
|
[source,java]
|
|
----
|
|
@Test
|
|
void test() { // Refactor this method.
|
|
assertEquals(1, f(1));
|
|
assertEquals(2, f(2));
|
|
assertEquals(3, g(1));
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
void test_f() {
|
|
assertEquals(1, f(1));
|
|
assertEquals(2, f(2));
|
|
}
|
|
void test_g() {
|
|
assertEquals(3, g(1));
|
|
}
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Refactor this method to reduce the number of assertions from {number of assertions} to less than {default value}.
|
|
|
|
|
|
=== Parameters
|
|
|
|
.maximumAssertionNumber
|
|
****
|
|
|
|
----
|
|
25
|
|
----
|
|
|
|
The maximum authorized number of assertions in a test method.
|
|
****
|
|
|
|
|
|
=== Highlighting
|
|
|
|
Primary locations:
|
|
|
|
* Method name
|
|
|
|
Secondary locations:
|
|
|
|
* Assertions
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|