Question

Why does 'mvn test' work for me but not 'mvn surefire:test' when using TestNG? Its interesting because the location of the suite xml file is configured via the surefire plugin but it only runs when I execute with the regular Maven 'test' goal. When I use 'mvn surefire:test', then its as if the resource (or src/test/resources/testng.xml) file is not visible to the test executor when the file physically seems to exist at the expected location: /target/test-classes/testng.xml .

Here is my configuration.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>${maven-surefire.version}</version>
    <configuration>
        <includes>
      <include>Tests/**/*.java</include>
        </includes>
        <suiteXmlFiles>
            <suiteXmlFile>
                 ${project.build.testOutputDirectory}/${testng.suitexmlfile}
                    </suiteXmlFile>
        </suiteXmlFiles>
        <configuration>
            <systemPropertyVariables>
                <build-name>${testng.buildname}</build-name>
                <testenv>${testng.testenv}</testenv>
            </systemPropertyVariables>
            <groups>${testng.groups}</groups>
        </configuration>
    </configuration>
</plugin>
Was it helpful?

Solution

mvn surefire:test won't find any tests to execute if the sources haven't been compiled before.

Therefore this won't find any tests to execute:

mvn clean
mvn surefire:test

This however should work (because mvn test is bound to the maven lifecycle and compiles the sources before executing the tests):

mvn clean
mvn test
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top