通常你不需要任何特別的與TestNG的關係。只需使用maven-surefire插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
</plugin>
並基於所有正確註釋的測試應運行。啊,當然你需要這樣的依賴關係TestNG的:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.5.2</version>
<scope>test</scope>
</dependency>
通常我不會創建測試套件了,導致這個,你必須保持它常常被漏診更新等只使用註釋的點。
如果您需要運行一個特定的測試套件,只需在src/test/resources中定義一個testng.xml文件,並適當增強maven-surefire plugin的配置。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
我在這裏找到了答案:http://stackoverflow.com/questions/11762801/run-junit-suite-using-maven-command – Philippe