title: How to pass java code a parameter from maven for testing
body: <p>I need to pass on following values …</p>
  
  <p><strong>exeEvironment</strong>  (Test environment) , 
  <strong>testGroup</strong> (Group in testNG)</p>
  
  <p>from Command-Line -> POM -> TestNG -> Test cases. </p>
  
  <p>Based on these two posts .... </p>
  
  <p><a href="https://stackoverflow.com/questions/9622121/pass-a-java-parameter-from-maven">pass a java parameter from maven</a></p>
  
  <p><a href="https://stackoverflow.com/questions/6280576/how-to-pass-parameters-to-guicified-testng-test-from-surefire-maven-plugin">How to pass parameters to guicified TestNG test from Surefire Maven plugin?</a></p>
  
  <p>I did the following configuration ..  </p>
  
  <p>In <strong>surefire plugin</strong>, I tried following two options, none seem to work. </p>
  
  <p>=====</p>
  
  <p>(1)</p>
  
  <pre class="lang-xml prettyprint-override"><code>  &lt;execution&gt;
  &lt;id&gt;default-test&lt;/id&gt;
      &lt;goals&gt;
          &lt;goal&gt;test&lt;/goal&gt;
      &lt;/goals&gt;
      &lt;configuration&gt;
          &lt;properties&gt;
              &lt;exeEnvironment&gt;${exeEnvironment}&lt;/exeEnvironment&gt;
              &lt;testGroup&gt;${testGroup}&lt;/testGroup&gt;
          &lt;/properties&gt;
          &lt;suiteXmlFiles&gt;
              &lt;suiteXmlFile&gt;testng.xml&lt;/suiteXmlFile&gt;
          &lt;/suiteXmlFiles&gt;
      &lt;/configuration&gt;
  &lt;/execution&gt;
  </code></pre>
  
  <hr>
  
  <p>(2)</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;execution&gt;
  &lt;id&gt;default-test&lt;/id&gt;
  &lt;goals&gt;
      &lt;goal&gt;test&lt;/goal&gt;
  &lt;/goals&gt;
  &lt;configuration&gt;
      &lt;systemPropertyVariables&gt; &lt;exeEnvironment&gt;${exeEnvironment}&lt;/exeEnvironment&gt; 
          &lt;testGroup&gt;${testGroup}&lt;/testGroup&gt; &lt;/systemPropertyVariables&gt; 
      &lt;suiteXmlFiles&gt;
          &lt;suiteXmlFile&gt;testng.xml&lt;/suiteXmlFile&gt;
      &lt;/suiteXmlFiles&gt;
  &lt;/configuration&gt;
  &lt;/execution&gt;
  </code></pre>
  
  <hr>
  
  <p>In <strong>testNG.xml</strong> , can I use the the variable <code>testGroup</code> like …</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;test name="Web Build Acceptance"&gt;
      &lt;groups&gt;
          &lt;run&gt;
              &lt;include name="${testGroup} /&gt;
          &lt;/run&gt;
      &lt;/groups&gt;
      &lt;classes&gt;
          &lt;class name="com.abc.pqr" /&gt;
      &lt;/classes&gt;
  &lt;/test&gt;
  </code></pre>
  
  <p>This doesn't seem to work as well, do I need to define a parameter. </p>
  
  <hr>
  
  <p>In the <strong>test cases</strong> , I tried to get he variables in following two ways ….
  (1)</p>
  
  <pre class="lang-java prettyprint-override"><code>testEnv = testContext.getSuite().getParameter("exeEnvironment");
  testGroup = testContext.getSuite().getParameter("testGroup");
  </code></pre>
  
  <p>(2) </p>
  
  <pre class="lang-java prettyprint-override"><code>testEnv = System.getProperty("exeEnvironment");
  testGroup = System.getProperty("testGroup");
  </code></pre>
  
  <hr>