title: Access fields of a TestNG test class from a TestListenerAdapter
body: <p><strong>Background</strong></p>
  
  <p>I have the following situation:</p>
  
  <ul>
  <li>My test-classes implement <code>org.testng.ITest</code></li>
  <li>They all have a <code>Helper</code> containing info on the current test environment (e.g. device-under-test)</li>
  </ul>
  
  <p>For example:</p>
  
  <pre><code>com.company.appundertest.Helper h;
  
  public class TestClass implements org.testng.ITest {
      private String testName;
  
      //Helper is initialized externally in Factory + DataProvider 
      //and passed to Constructor.
      public TestClass(com.company.appundertest.Helper hh) {
  
      this.h = hh;
  
      //constructor sets the test-name dynamically
      //to distinguish multiple parallel test runs.
      this.testName = "some dynamic test name";
      }
  
      @Override
      public String getTestName() {
          return this.testName;
      }
  
      @Test
      public void failingTest() {
          //test that fails...
      }
  }
  </code></pre>
  
  <ul>
  <li>These test-classes are executed in parallel using Factory and parallel data-provider. </li>
  <li>Upon Test Failure, I need to access variables <em>within the Helper instance of the failing test-class</em>. These will be used to identify the environment at the point of failure (e.g. take screenshot on failing device). </li>
  </ul>
  
  <p>This problem essentially boils down to:</p>
  
  <p><strong>How would I access fields within the TestNG test-class?</strong></p>
  
  <p><strong>References</strong></p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/3567372/access-to-private-inherited-fields-via-reflection-in-java">Access to private inherited fields via reflection in Java</a></li>
  </ul>