Assume these tools are used for running tests in a maven project:
org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5
with default configurationorg.junit.jupiter:junit-jupiter-engine:5.7.0
Please, find minimal example here.
The project consists of one java module (java 11
, maven 3.6.1
).
With this setup given a typical successful test looks like:
public class SampleTest {
@Test
public void test() {
assertEquals(1, 1);
}
}
I would like to avoid using public
for all test methods and test classes, because it makes only visual noise. Unfortunately, after removing public
visibility the test fails to start.
class SampleTest {
@Test
void test() {
assertEquals(1, 1);
}
}
mvn test
...
java.lang.reflect.InaccessibleObjectException:
Unable to make org.sample.SampleTest.test() accessible:
module sample.core does not "opens org.sample" to unnamed module @7d9d1a19
Please, help me to find a proper way to configure the surefire plugin, so it could run tests without requiring public
everywhere.
If needed, change version of surefire and junit - they are here just for clarity.