1. 程式人生 > >Maven執行TestNG的testcase 兩種方式,一種testng.xml,一種testngCase.java

Maven執行TestNG的testcase 兩種方式,一種testng.xml,一種testngCase.java

詳情參照:

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" - includes all of its subdirectories and all Java filenames that end with "Test".
"**/*TestCase.java" - includes all of its subdirectories and all Java filenames that end with "TestCase
Ps:以上命名規範在pom檔案中自定義配置,關鍵程式碼如下:
  <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>
PS:  .xml檔案必須在工程的主目錄之下。

3.maven整合reportNG生成Html格式的測試報告:
在pom檔案的dependencies中新增三個dependency:
velocity   /guice   /reportng

同時修改上述pom檔案的maven-surefire-plugin部分程式碼:
 <configuration>
         <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>

--------------------- 
作者:wuwh無非 
來源:CSDN 
原文:https://blog.csdn.net/wwhrestarting/article/details/46596869?utm_source=copy 
版權宣告:本文為博主原創文章,轉載請附上博文連結!