简体   繁体   中英

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

I cannot make these two work together in eclipse

I can set up surefire plugin like this

<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.

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...

but maven-compiler-plugin:2.3.2:testCompile isn't setup like surefire plugin via the testResources configuration. It just compiles test source code into test-classes

What should I do to make testNG execute as if I run surefire plugin? I somehow need the effect that results from <testResources>

testResources & resources is part of maven-resources-plugin

compile & test-compile is part of maven-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

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. 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

/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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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