title: InaccessibleObjectException when running tests
body: <p>I created the first test for a project as below:</p>
  
  <pre><code>package my.module.sub;
  
  import org.junit.jupiter.api.Test;
  
  public class FirstTest {
  
    @Test
    void firstTest() {
      System.out.println("Tests are now running");
    }
  
  }
  </code></pre>
  
  <p>But when I run the tests I get the below error:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>It seems that if I add <code>opens my.module.sub</code> to the <code>module-info.java</code> file the test will run fine.</p>
  
  <p>Obviously I would rather that not be there. So what is the best way to prevent this error from occurring?</p>