Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

maven

testng

I see a lot of posts on here about running a TestNG suite using Maven surefire plugin. The examples say to add this to the pom:

<configuration>
    <suiteXmlFiles>
        <suiteXmlFile>${testSuite}</suiteXmlFile>
    </suiteXmlFiles>
</configuration>

And then this to the command line:

mvn test -DtestSuite=myCustomSuite.xml

My problem with this is that it ties you to using the TestNG suite... For example, if I want to run with groups like this:

mvn test -Dgroups=myGroup

I get this error:

maven-surefire-plugin:2.18.1:test failed: testSuiteXmlFiles0 has null value

I want to be able to run, from command line, passing in either a suite path or groups.

like image 572
zmorris Avatar asked Jun 23 '15 20:06

zmorris


1 Answers

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>
like image 184
juherr Avatar answered Oct 12 '22 10:10

juherr