pom.xml

<build>
     <plugins>
         <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-compiler-plugin</artifactId>
             <version>3.6.1</version>
             <configuration>
                 <source>1.6</source>
                 <target>1.6</target>
             </configuration>
         </plugin>
         <!--添加插件 关联testNg.xml-->
         <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-surefire-plugin</artifactId>
             <version>2.2</version>
             <configuration>
                 <testFailureIgnore>true</testFailureIgnore>
                 <suiteXmlFiles>
                     <file>res/testNG.xml</file>
                 </suiteXmlFiles>
                 <!--<workingDirectory>res/</workingDirectory>-->
             </configuration>
         </plugin>
     </plugins>
 </build>

 <dependencies>
     <dependency>
         <groupId>org.testng</groupId>
         <artifactId>testng</artifactId>
         <version>6.11</version>
     </dependency>

testng.xml

<suite name="TesterHome" parallel="tests" thread-count="2"> <!-- 并行地执行test套件-->
    <parameter name="appURL" value="https://testerhome.com/account/sign_in"/>
    <parameter name="browserType" value="chrome"/>
    <parameter name="driverPath" value="C:\Program Files (x86)\Google\Chrome\Application\"/>
    <listeners>
        <listener class-name="util.ExtentTestNGIReporterListener"/> <!-- 测试报告-->
        <listener class-name="util.TestMonitor"/> <!-- 打印日志-->
    </listeners>
    <test name="登录">
        <classes>
            <class name="test.LoginPageTest"/>
        </classes>
    </test>
    <test name="社区">
        <classes>
            <class name="test.MyinfoPageTest"/>
        </classes>
    </test>
</suite>

执行命令:

mvn clean test -Dsurefire.suiteXmlFiles=res\testng.xml

执行命令后出现 No tests to run,也没有其他错误,请问下如何才能用 maven 来执行 testng?


↙↙↙阅读原文可查看相关链接,并与作者交流