rspec/rules/S5961/java/rule.adoc

52 lines
1000 B
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
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
2021-04-28 16:49:39 +02:00
With a parameter of 2.
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
@Test
void test() { // Refactor this method.
assertEquals(1, f(1));
assertEquals(2, f(2));
assertEquals(3, g(1));
}
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
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)
include::message.adoc[]
include::parameters.adoc[]
include::highlighting.adoc[]
endif::env-github,rspecator-view[]