繁体   English   中英

如何使 maven-surefire-plugin 与 Eclipse 中的 TestNG 一起工作

[英]How to make maven-surefire-plugin work with TestNG in Eclipse

我不能让这两个在 eclipse 中一起工作

我可以像这样设置surefire插件

<suiteXmlFiles>
        <suiteXmlFile>${basedir}/src/test/resources/testng.xml</suiteXmlFile>
    </suiteXmlFiles>
    <testResources>
        <testResource>
            <directory>${project.basedir}/src/test/java</directory>
            <includes>
                <include>**/*.*</include>
            </includes>
        </testResource>
        <testResource>
            <directory>${project.basedir}/src/test/resources</directory>
            <includes>
                <include>**/*</include>
            </includes>
        </testResource>
    </testResources>

并运行$mvn test并且所有资源都被编译并移动到/target/test-classes ,它工作正常。

但是,如果我运行$mvn clean然后使用 TestNG 视图运行一些测试,则/target/test-classes中没有编译任何内容,因此我要么必须在此之前运行测试阶段,要么以某种方式使用maven-compiler-plugin:testCompile目标编译测试资源...

但是maven-compiler-plugin:2.3.2:testCompile没有像通过testResources配置的surefire插件那样设置。 它只是将测试源代码编译成测试类

我应该怎么做才能让 testNG 像运行surefire插件一样执行? 我不知何故需要<testResources>产生的效果

testResources & resourcesmaven-resources-plugin的一部分

compile & test-compilemaven-compiler-plugin的一部分

因此,您所要做的就是在通过 TestNG 视图运行测试之前单击调用所有这些阶段和目标的按钮

compile 
test-compile
maven-resources-plugin:resources 
maven-resources-plugin:testResources 

Also, and this is very important, whenever you run test(s) from the TestNG view, eclipse creates a temporary testng.xml definition with the test(s) you have clicked on, either a test or a class of tests. 因此,如果您使用 testNG 通过 Eclipse 的运行方式运行配置,那么通过 SureFire 插件运行时您在 testng.xml 中的其他设置会丢失...它看起来像这样

/tmp/testng-eclipse-388280625/testng-customsuite.xml

-

<suite name="Default suite">
  <test verbose="2" name="Default test">
    <classes>
      <class name="com.example.tests.selenium.SubmitUploadFormTest"/>
    </classes>
  </test>
</suite>

它有一个方便的方法来处理这个问题 - 在 eclipse Z3327777618BCF7CEFAZ 首选项中设置模板 testng.xml 文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM