简体   繁体   English

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

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

I cannot make these two work together in eclipse我不能让这两个在 eclipse 中一起工作

I can set up surefire plugin like this我可以像这样设置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>

and run $mvn test and all resources are compiled and moved into /target/test-classes , which works fine.并运行$mvn test并且所有资源都被编译并移动到/target/test-classes ,它工作正常。

But if I run $mvn clean and then use the TestNG view to run some tests, there is nothing compiled in /target/test-classes , so that I either have to run test phase before that, or somehow employ maven-compiler-plugin:testCompile goal to compile test resources...但是,如果我运行$mvn clean然后使用 TestNG 视图运行一些测试,则/target/test-classes中没有编译任何内容,因此我要么必须在此之前运行测试阶段,要么以某种方式使用maven-compiler-plugin:testCompile目标编译测试资源...

but maven-compiler-plugin:2.3.2:testCompile isn't setup like surefire plugin via the testResources configuration.但是maven-compiler-plugin:2.3.2:testCompile没有像通过testResources配置的surefire插件那样设置。 It just compiles test source code into test-classes它只是将测试源代码编译成测试类

What should I do to make testNG execute as if I run surefire plugin?我应该怎么做才能让 testNG 像运行surefire插件一样执行? I somehow need the effect that results from <testResources>我不知何故需要<testResources>产生的效果

testResources & resources is part of maven-resources-plugin testResources & resourcesmaven-resources-plugin的一部分

compile & test-compile is part of maven-compiler-plugin compile & test-compilemaven-compiler-plugin的一部分

So that all you have to do is to click a button that invokes all these phases & goals before you run tests via TestNG view因此,您所要做的就是在通过 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. 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. So that additional settings in testng.xml that you have when running via SureFire plugin gets lost if you are using testNG run configuration via Eclipse's Run As... it looks like this因此,如果您使用 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>

It has a convenient way to deal with this - setting up a template testng.xml file in eclipse testng preferences.它有一个方便的方法来处理这个问题 - 在 eclipse Z3327777618BCF7CEFAZ 首选项中设置模板 testng.xml 文件。

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

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