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

冷暖自知 提交于 2019-11-29 20:53:22

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.

Lyle

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.

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.

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

mvn integration-test -Dtest=aITest -DfailIfNoTests=false

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!