Maven執行TestNG的testcase 兩種方式
阿新 • • 發佈:2019-02-07
詳情參照:
http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html
1.maven通過maven-surefire-plugin來執行maven專案中src/test/java資料夾下的testcase:
預設情況下,testcase的命名規範必須是以下三種之一:
- "**/Test*.java" - includes all of its subdirectories and all Java filenames that start with "Test".
- "**/*Test.java"
- "**/*TestCase.java" - includes all of its subdirectories and all Java filenames that end with "TestCase
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.18.1</version> <configuration> <includes> <include>Sample.java</include> </includes> </configuration> </plugin> </plugins> </build>
2.maven通過maven-surefire-plugin外掛來執行工程目錄主路徑下的testng.xml(可配置)
<plugins> [...] <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.18.1</version> <configuration> <suiteXmlFiles> <suiteXmlFile>testng.xml</suiteXmlFile> </suiteXmlFiles> </configuration> </plugin> [...] </plugins>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<properties>
<!-- Setting ReportNG listeners -->
<property>
<name>listener</name>
<value>org.uncommons.reportng.HTMLReporter, org.uncommons.reportng.JUnitXMLReporter</value>
</property>
</properties> </configuration>