How to run individual test in the integration-test target in maven

后端 未结 6 1388
囚心锁ツ
囚心锁ツ 2020-12-23 21:36

We have a hundreds of tests defined for our integration-test phase lifecycle in maven, and they take a long time to finish.

What I want to do is run just one test in

相关标签:
6条回答
  • 2020-12-23 22:01

    just add -DfailIfNoTests=false works for me with testNG. Something like this:

    mvn integration-test -Dtest=aITest -DfailIfNoTests=false
    
    0 讨论(0)
  • 2020-12-23 22:01

    Just ran into this myself. Something like this worked well for me:

    mvn -Pintegration-test -Dtest=<my-test>
    

    The trick was to ensure that the test-group was mentioned before the -Dtest portion.

    0 讨论(0)
  • 2020-12-23 22:06

    I'm not sure about JUnit, but for TestNG the strategy would be to define a suite XML file with only the one test, and then in your POM configure the surefire plugin to only run that. In your POM, you would have something like this (disclaimer, this is untested):

      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <executions>
          <execution>
            <phase>integration-test</phase>
            <configuration>
              <suiteXmlFiles>
                <suiteXmlFile>single-test.xml</suiteXmlFile>
              </suiteXmlFiles>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    

    To configure the suite file, see http://testng.org/doc/documentation-main.html

    0 讨论(0)
  • 2020-12-23 22:11

    The Failsafe documentation would have you specify the test like so:

    mvn -Dit.test=BrokenIT verify
    

    However, -Dit.test does not appear to work any longer. Rather, the same parameter used to specify a Surefire test will apparently work for Failsafe as well. For example:

    mvn -Dtest=WorksIT verify
    

    I've filed a bug (EDIT: which was closed as "Cannot Reproduce" in 2.12) to correct the documentation.

    0 讨论(0)
  • 2020-12-23 22:13

    I struggled through this, and I created an additional profile to use when I wanted to run just one integration test. I hope that I've successfully extracted just the right part here:

        <profile>
            <id>integrationTestSingle</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>surefire-it</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>test</goal>
                                </goals>
                                <configuration>
                                    <includes>
                                        <include>**/integration/**/${test}.java</include>
                                    </includes>
                                    <skipTests>false</skipTests>
                                </configuration>
                            </execution>
                        </executions>
                        <configuration>
                            <argLine>-Xms256M -Xmx768M -XX:MaxPermSize=256M</argLine>
                        </configuration>
                    </plugin>
    
                    <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>default-test</id>                                
                                <configuration>
                                    <skipTests>true</skipTests>
                                </configuration>
                            </execution>
                        </executions>
    
                    </plugin>
                </plugins>
            </build>
        </profile>
    

    Now, I call maven with the integrationTestSingle profile and with -DfailIfNoTests=false -Dtest=NameOfTest, and it doesn't run any of the regular tests during the regular "test" phase, and runs just the NameOfTest test during the integration-test phase.

    0 讨论(0)
  • 2020-12-23 22:16

    If you're using the Maven failsafe plugin, you can run a single integration test by setting the it.test property to your fully qualified test class name:

    mvn -Dit.test=your.TestCase verify
    

    See the failsafe plugin docs for more info.

    0 讨论(0)
提交回复
热议问题