I created the first test for a project as below:
package my.module.sub;
import org.junit.jupiter.api.Test;
public class FirstTest {
@Test
void firstTest() {
System.out.println("Tests are now running");
}
}
But when I run the tests I get the below error:
java.lang.reflect.InaccessibleObjectException: Unable to make void my.module.sub.FirstTest.firstTest() accessible: module my.module does not "opens my.module.sub" to unnamed module @7dc0f706
It seems that if I add opens my.module.sub
to the module-info.java
file the test will run fine.
Obviously I would rather that not be there. So what is the best way to prevent this error from occurring?
The issue turned out to be because firstTest()
was not public. So when running the tests, JUnit was not able to access the method.
In the end all I had to do to fix the issue was change firstTest()
to:
public void firstTest()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With