
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.
65 lines
1.4 KiB
Plaintext
65 lines
1.4 KiB
Plaintext
== Why is this an issue?
|
|
|
|
JUnit5 is more tolerant regarding the visibilities of Test classes than JUnit4, which required everything to be ``++public++``.
|
|
|
|
|
|
In this context, JUnit5 test classes can have any visibility but ``++private++``, however, it is recommended to use the default package visibility, which improves readability of code.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
public class MyClassTest { // Noncompliant - modifier can be removed
|
|
@Test
|
|
protected void test() { // Noncompliant - modifier can be removed
|
|
// ...
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
class MyClassTest {
|
|
@Test
|
|
void test() {
|
|
// ...
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
=== Exceptions
|
|
|
|
This rule does not raise an issue about ``++private++`` visibility, because ``++private++`` test methods and classes are systematically ignored by JUnit5, without a proper warning. It's not a ``++Code Smell++`` but a ``++Bug++`` handled by the rule S5810 .
|
|
|
|
|
|
== Resources
|
|
|
|
* https://junit.org/junit5/docs/current/user-guide/#writing-tests-classes-and-methods[JUnit 5 Test Classes and Methods]
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Remove this '[public|protected]' modifier.
|
|
|
|
|
|
=== Highlighting
|
|
|
|
wrong visibility modifier of the test method/class
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|