title: TestNG: Running test programmatically - parameters set on XmlTest object are null when executing test method
body: <p>I want to run Test Suite programmatically with TestNG.</p>
  
  <p>I created test structurde: XmlSuite -> XmlTest -> TestClass (which extends XmlClass)</p>
  
  <p>I'm doing three things:</p>
  
  <ul>
  <li>adding parameter to XmlTest with addParameter(String, String)</li>
  <li>setting parameter to TestClass with setParameters(Map)</li>
  <li>setting variable Day in TestClass</li>
  </ul>
  
  <p>But what happens on test execution is when it goes to @Test method the object doesn't have things which I set before.</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>public class TestRunner {
      public static void main(String[] args) {
          XmlSuite suite = new XmlSuite();
          suite.setName("TmpSuite");
  
          XmlTest test = new XmlTest(suite);
          test.setName("TmpTest");
          // Add parameter to XmlTest
          test.addParameter("testParam1", "clock");
  
          TestClass testClass = new TestClass();
  
          // Add parameter to XmlClass
          Map&lt;String, String&gt; testClassParameters = new HashMap&lt;&gt;();
          testClassParameters.put("classParam1", "valueOfClassParam1");
          testClass.setParameters(testClassParameters);
  
          // Set day variable
          testClass.setDay("Friday");
          testClass.setClass(TestClass.class);
  
          test.setXmlClasses(Arrays.asList(testClass)) ;
  
          TestNG tng = new TestNG();
          tng.setXmlSuites(Arrays.asList(suite));
  
          tng.run();
      }
  }
  
  public class TestClass extends XmlClass {
  
      private String day;
  
      @Test
      public void test1() {
          System.out.println("Day: " + day);
          System.out.println("LocalParameters: " + getLocalParameters());
          System.out.println("AllParameters: " + getAllParameters());
      }
  
      public void setDay(String day) {
          this.day = day;
      }
  }
  </code></pre>
  
  <p><strong>Result:</strong></p>
  
  <pre><code>Day: null
  LocalParameters: {}
  ------------&gt; Exception
  </code></pre>