Reputation: 1412
A bit of a newbie here, but I'm trying to use the Maven Failsafe plugin to run TestNG tests in my Java project using the Maven task in TFS 2015. I originally used the Surefire plugin but wanted to use Failsafe instead, and when changing the code slightly according to documentation for TestNG, the Failsafe plugin will run the TestNG test class instead of the test suite (and fail because I'm using parameters). When switching back to Surefire, the tests run as a test suite and pass.
I've tried different versions of Failsafe and that hasn't changed anything. Is there anything that I'm missing that Failsafe needs to recognize a test suite?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
(with Surefire)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
(testng.xml)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<parameter name="urlsource" value="https://httpbin.org/get"></parameter>
<test name="Test">
<classes>
<class name="test.java.TestGenericRESTAPI"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
Upvotes: 3
Views: 2701
Reputation: 24869
Your configuration didn't run Failsafe for me at all, only Surefire. As per Failsafe docs, I configured goals:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
Now both Surefire and Failsafe execute tests on mvn verify
(and Failsafe passes parameters correctly). If you want to skip Surefire tests, you can do this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
Now Surefire still runs on mvn verify
, but doesn't actually run any tests. I don't know how to disable Surefire completely, so any suggestions or improvements are welcome.
Note that your IDE may still invoke Surefire directly (NetBeans does for me). Some IDE-specific settings may help here.
Upvotes: 0