Run TestNG suite from maven getting error:maven-surefire-plugin:test failed: testSuiteXmlFiles0 has null value

Instead of using your surefire configuration with a property, you can:

  1. Remove the surefire configuration and replace mvn test -DtestSuite=myCustomSuite.xml by mvn test -Dsurefire.suiteXmlFiles=myCustomSuite.xml. See Surefire documentation
  2. Continue to use the mvn test -Dgroups=myGroup.

As the surefire configuration will be removed, the error testSuiteXmlFiles0 has null value won't be present with the -Dgroup option.

You can also use maven profiles which will configure surefire plugin depending on which property you pass to maven.

<profiles>
  <profile>
    <id>suite</id>
    <activation>
      <property>
        <name>testSuite</name>
      </property>
    </activation>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <configuration>
        <suiteXmlFiles>
          <suiteXmlFile>${testSuite}</suiteXmlFile>
        </suiteXmlFiles>
      </configuration>
    </plugin>
  </profile>
</profiles>

Tags:

Java

Testng

Maven