title: JUnit 5 How to get the instance of parent test form a nested test class
body: <p>I am implementing a <a href="https://github.com/mockito/mockito/pull/1221" rel="nofollow noreferrer">Mockito extension for JUnit 5</a>. Assume we are in a nested test and want to create mocks for the parent test class.</p>
  
  <pre><code>class RootTest{
    @Mock Foo mock;
  
    @Nested
    class NestedTest{
      @Test
      public void foo(){
         mock.bar();
      }
    }
  }
  </code></pre>
  
  <p>To do that we need the instance of the <code>RootTest</code> in order to assign the mocks to the fields annotated with <code>@Mock</code>.
  The current problem is to obtain the instance of the <code>RootTest</code> class. The first attempt was to get it via <code>ExtensionContext.getParent()</code> and <code>ExtensionContext.getTestInstance()</code> but the test instance is <code>null</code> for the parent. </p>
  
  <p>Q: How to get the parent instance of the nested class? Reflection might help but is not an option, cause it is compiler dependent.</p>