Selenium mvn test 提示 No tests to run

测试小书童 · May 18, 2017 · Last by 测试小书童 replied at May 23, 2017 · 3257 hits

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?

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 8 条回复 时间 点赞

test.LoginPageTest 是否有@Test

小胖。 回复
public class LoginPageTest extends TestBaseSetup {
    private WebDriver driver;

    @BeforeClass
    public void setUp() {
        driver=getDriver();
    }
    @Test
    public void testLogin() throws YamlException, FileNotFoundException, InterruptedException {
        LoginPage loginPage = new LoginPage(this.driver, "/Login.yaml");
        loginPage.operate();
        Assert.assertTrue(loginPage.checkpoint(), "检查点不通过");
    }
}

有的

maven 虽然在用 也不是狠了解,建议先试下直接用 testng.xml 执行,如果可以再试下用 clean install..坐等大神来看

看看 Test 注解导入的包是不是搞成 Junit 了?

是不是文件放错了文件夹

我一般不用配置文件,而采用 maven-surefire-plugin 自动扫描 Case 的方法运行 Case

  <configuration>
                   <includes>
                       <include>**/testcase/*Test.java</include>
                   </includes>
</configuration>

测试用例不是应该要写在 src/test/java?

测试小书童 关闭了讨论 23 May 16:54
测试小书童 重新开启了讨论 23 May 16:54

问题解决,我用的集成测试启动 testng.xml

关键配置如下:

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.20</version>
        <configuration>
            <suiteXmlFiles>
                <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
            </suiteXmlFiles>
        </configuration>
        <executions>
        <execution>
            <id>failsafe-integration-tests</id>
            <phase>integration-test</phase>
            <goals>
                <goal>integration-test</goal>
            </goals>
        </execution>
    </executions>
    </plugin>

直接执行 mvn test 即可

测试小书童 关闭了讨论 23 May 16:56
需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up