title: How to run a selected suiteXmlFile via maven surefire plugin
body: <p>I have gone through all related questions on SO. But I think my question is little different than others.</p>
  
  <p>I have following suite xml files</p>
  
  <p><strong>Initialize.xml</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"&gt;
  &lt;suite name="Start" verbose="1" parallel="tests"
      thread-count="5" configfailurepolicy="continue"&gt;
  
  
      &lt;test name="Initialize" annotations="JDK" preserve-order="true"&gt;
          &lt;parameter name="tags" value="not @42" /&gt;
          &lt;classes&gt;
              &lt;class name="com.example.runner.InitializeExecution" /&gt;
          &lt;/classes&gt;
      &lt;/test&gt;
  
  &lt;/suite&gt;
  </code></pre>
  
  <p><strong>Conclude.xml</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"&gt;
  &lt;suite name="Start" verbose="1" parallel="tests"
      thread-count="5" configfailurepolicy="continue"&gt;
  
      &lt;test name="Conclude" annotations="JDK" preserve-order="true"&gt;
          &lt;parameter name="tags" value="not @42" /&gt;
          &lt;classes&gt;
              &lt;class name="com.example.runner.ConcludeExecution" /&gt;
          &lt;/classes&gt;
      &lt;/test&gt;
  
  &lt;/suite&gt;
  </code></pre>
  
  <p><strong>smoke.xml</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"&gt;
  &lt;suite name="smoke" verbose="1" parallel="tests"
      thread-count="3" configfailurepolicy="continue" data-provider-thread-count="2"&gt;
  
  
      &lt;test name="Smoke" annotations="JDK" preserve-order="true"&gt;
          &lt;parameter name="tags" value="@dm1" /&gt;
          &lt;classes&gt;
              &lt;class name="com.example.runner.smoke" /&gt;
          &lt;/classes&gt;
      &lt;/test&gt;
  
  
  &lt;/suite&gt;
  </code></pre>
  
  <p><strong>regression.xml</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"&gt;
  &lt;suite name="smoke" verbose="1" parallel="tests"
      thread-count="3" configfailurepolicy="continue" data-provider-thread-count="2"&gt;
  
  
      &lt;test name="Regression" annotations="JDK" preserve-order="true"&gt;
          &lt;parameter name="tags" value="@dm1" /&gt;
          &lt;classes&gt;
              &lt;class name="com.example.runner.regression" /&gt;
          &lt;/classes&gt;
      &lt;/test&gt;
  
  
  &lt;/suite&gt;
  </code></pre>
  
  <p><strong>pom.xml snippets</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>                &lt;plugin&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
                      &lt;version&gt;2.21.0&lt;/version&gt;
                      &lt;configuration&gt;
                          &lt;properties&gt;
                              &lt;property&gt;
                                  &lt;name&gt;dataproviderthreadcount&lt;/name&gt;
                                  &lt;value&gt;2&lt;/value&gt;
                              &lt;/property&gt;
                          &lt;/properties&gt;
                          &lt;suiteXmlFiles&gt;
                              &lt;suiteXmlFile&gt;Initialize.xml&lt;/suiteXmlFile&gt;
                              &lt;suiteXmlFile&gt;${suiteXmlFile}&lt;/suiteXmlFile&gt;
                              &lt;suiteXmlFile&gt;Conclude.xml&lt;/suiteXmlFile&gt;
                          &lt;/suiteXmlFiles&gt;
                      &lt;/configuration&gt;
                  &lt;/plugin&gt;
  </code></pre>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;dependency&gt;
      &lt;groupId&gt;org.testng&lt;/groupId&gt;
      &lt;artifactId&gt;testng&lt;/artifactId&gt;
      &lt;version&gt;6.14.3&lt;/version&gt;
      &lt;!-- &lt;scope&gt;compile&lt;/scope&gt; --&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>I need to execute initialize.xml then either of smoke.xml or regression.xml then conclude.xml in sequential order.
  Consider the following set as an example:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;suiteXmlFiles&gt;
       &lt;suiteXmlFile&gt;Initialize.xml&lt;/suiteXmlFile&gt;
       &lt;suiteXmlFile&gt;smoke.xml&lt;/suiteXmlFile&gt;
                 &lt;!-- or --&gt;
  &lt;!-- &lt;suiteXmlFile&gt;regression.xml&lt;/suiteXmlFile&gt; --&gt;
       &lt;suiteXmlFile&gt;Conclude.xml&lt;/suiteXmlFile&gt;
  &lt;/suiteXmlFiles&gt;
  </code></pre>
  
  <p>How can I parameterize middle suiteXmlFile from pom? I tried using below command but its not working and throwing exception.</p>
  
  <pre><code>mvn clean test -Dsurefire.suiteXmlFile=smoke.test
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>[ERROR] org.apache.maven.surefire.booter.SurefireExecutionException: Exception in provider
  [ERROR]     at org.apache.maven.plugin.surefire.InPluginVMSurefireStarter.runSuitesInProcess(InPluginVMSurefireStarter.java:91)
  [ERROR]     at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1132)
  [ERROR]     at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:978)
  [ERROR]     at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:854)
  [ERROR]     at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
  [ERROR]     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
  [ERROR]     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
  [ERROR]     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
  [ERROR]     at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
  [ERROR]     at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
  [ERROR]     at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
  [ERROR]     at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
  [ERROR]     at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
  [ERROR]     at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
  [ERROR]     at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
  [ERROR]     at org.apache.maven.cli.MavenCli.execute(MavenCli.java:956)
  [ERROR]     at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:290)
  [ERROR]     at org.apache.maven.cli.MavenCli.main(MavenCli.java:194)
  [ERROR]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  [ERROR]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  [ERROR]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  [ERROR]     at java.lang.reflect.Method.invoke(Method.java:498)
  [ERROR]     at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
  [ERROR]     at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
  [ERROR]     at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
  [ERROR]     at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
  [ERROR] Caused by: java.lang.NullPointerException
  [ERROR]     at org.apache.maven.surefire.testng.TestNGXmlTestSuite.locateTestSets(TestNGXmlTestSuite.java:97)
  [ERROR]     at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:119)
  [ERROR]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  [ERROR]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  [ERROR]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  [ERROR]     at java.lang.reflect.Method.invoke(Method.java:498)
  [ERROR]     at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray2(ReflectionUtils.java:206)
  [ERROR]     at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:160)
  [ERROR]     at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:83)
  [ERROR]     at org.apache.maven.plugin.surefire.InPluginVMSurefireStarter.runSuitesInProcess(InPluginVMSurefireStarter.java:87)
  [ERROR]     ... 25 more
  [ERROR] -&gt; [Help 1]
  [ERROR] 
  [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
  [ERROR] Re-run Maven using the -X switch to enable full debug logging.
  [ERROR] 
  [ERROR] For more information about the errors and possible solutions, please read the following articles:
  [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
  </code></pre>
  
  <p>If I use below command it is working but not executing initialize.xml and conclude.xml (Note the <strong>s</strong> in command)</p>
  
  <pre><code>mvn clean test -Dsurefire.suiteXmlFiles=smoke.test
  </code></pre>
  
  <p>I have also tried creating different suite xml like below and passing it through command line but its not working as I expected.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"&gt;
  
   &lt;suite name="Smoke Suite"  &gt; 
      &lt;suite-files&gt;
             &lt;suite-file path="./Initialize.xml" /&gt;
             &lt;suite-file path="./somke.xml" /&gt;
             &lt;suite-file path="./Conclude.xml" /&gt;
      &lt;/suite-files&gt;
  &lt;/suite&gt;
  </code></pre>
  
  <p>Please help. Any references or helpful links also appreciated.</p>