
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.
104 lines
1.8 KiB
Plaintext
104 lines
1.8 KiB
Plaintext
== Why is this an issue?
|
|
|
|
JUnit5 is more tolerant regarding the visibilities of Test classes and methods than JUnit4, which required everything to be public. JUnit5 supports default package, public and protected visibility, even if it is recommended to use the default package visibility, which improves the readability of code.
|
|
|
|
|
|
But JUnit5 ignores without any warning:
|
|
|
|
* private classes and private methods
|
|
* static methods
|
|
* methods returning a value without being a TestFactory
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
class MyClassTest {
|
|
@Test
|
|
private void test1() { // Noncompliant - ignored by JUnit5
|
|
// ...
|
|
}
|
|
@Test
|
|
static void test2() { // Noncompliant - ignored by JUnit5
|
|
// ...
|
|
}
|
|
@Test
|
|
boolean test3() { // Noncompliant - ignored by JUnit5
|
|
// ...
|
|
}
|
|
@Nested
|
|
private class MyNestedClass { // Noncompliant - ignored by JUnit5
|
|
@Test
|
|
void test() {
|
|
// ...
|
|
}
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
class MyClassTest {
|
|
@Test
|
|
void test1() {
|
|
// ...
|
|
}
|
|
@Test
|
|
void test2() {
|
|
// ...
|
|
}
|
|
@Test
|
|
void test3() {
|
|
// ...
|
|
}
|
|
@Nested
|
|
class MyNestedClass {
|
|
@Test
|
|
void test() {
|
|
// ...
|
|
}
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Remove this 'private' modifier.
|
|
|
|
Remove this 'static' modifier.
|
|
|
|
Replace the return type by void.
|
|
|
|
|
|
=== Highlighting
|
|
|
|
The modifier or the return type
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== on 20 May 2020, 14:17:02 Damien Urruty wrote:
|
|
There is a typo in this rule's description.
|
|
|
|
|
|
It should read: "But in any case, the 'private' modifier should not be used" instead of "But in any case, the 'private' modifier should be used".
|
|
|
|
endif::env-github,rspecator-view[]
|