如何使用故障安全插件分别触发集成测试? [英] How can I fire integration tests separately using failsafe-plugin?

查看:97
本文介绍了如何使用故障安全插件分别触发集成测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能运行集成测试,而只能运行单元测试.

I cannot run integration tests, but only unit tests.

这是我的Maven配置(请参见下面的代码).它使用两个插件.其中一个是maven-failsafe-plugin,第二个是maven-surefire-plugin.

Here is my Maven config (see code below). It uses two plugins. One of them is maven-failsafe-plugin and the second one is maven-surefire-plugin.

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <skipTests>false</skipTests>
    <skipITs>${skipTests}</skipITs>
    <skipUTs>${skipTests}</skipUTs>
</properties>
<dependencies>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.8.7</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.16</version>
            <configuration>
                <skipTests>${skipUTs}</skipTests>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.16</version>
            <configuration>
                <skipTests>${skipTests}</skipTests>
                <skipITs>${skipITs}</skipITs>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

我尝试使用此命令来运行单元测试

I try to run unit tests using this commend

mvn clean test

并且有单独启动集成测试的命令

And there is the command to start integration tests separately

mvn clean failsafe:integration-test verify

最后一条命令的调用结果为

Result of invocation of the last command is

[INFO] --- maven-failsafe-plugin:2.16:integration-test (default-cli) @ integration-test-demo ---
[INFO] No tests to run.

推荐答案

我为此使用配置文件:

<properties>
        <!-- Only unit tests are run by default. -->
        <skip.integration.tests>true</skip.integration.tests>
        <skip.unit.tests>false</skip.unit.tests>
    </properties>

个人资料

<profiles>
        <profile>
            <id>all-tests</id>
            <properties>
                <build.profile.id>all-tests</build.profile.id>
                <!-- All tests are run. -->
                <skip.integration.tests>false</skip.integration.tests>
                <skip.unit.tests>false</skip.unit.tests>
            </properties>
        </profile>
        <profile>
            <id>dev</id>
        </profile>
        <profile>
            <id>integration-tests</id>
            <properties>
                <!-- Used to locate the profile specific configuration file. -->
                <build.profile.id>integration-test</build.profile.id>
                <!-- Only integration tests are run. -->
                <skip.integration.tests>false</skip.integration.tests>
                <skip.unit.tests>true</skip.unit.tests>
            </properties>
        </profile>
    </profiles>

maven-surefire-plugin

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.15</version>
            <configuration>
                <!-- Skips unit tests if the value of skip.unit.tests property is true -->
                <skipTests>${skip.unit.tests}</skipTests>
                <!-- Excludes integration tests when unit tests are run. -->
                <excludes>
                    <exclude>**/*IntegrationTest.java</exclude>
                </excludes>
            </configuration>
        </plugin>

maven-failsafe-plugin

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.15</version>
            <executions>
                <!-- Ensures that both integration-test and verify goals of the Failsafe Maven plugin are executed. -->
                <execution>
                    <id>integration-tests</id>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                    <configuration>
                        <!-- Skips integration tests if the value of skip.integration.tests property is true -->
                        <skipTests>${skip.integration.tests}</skipTests>
                        <includes>
                            <include>**/*IntegrationTest.java</include>
                        </includes>
                    </configuration>
                </execution>
            </executions>
        </plugin>

集成测试以... IntegrationTest.java结尾,然后运行所需的配置文件(所有测试,集成测试).单元测试默认情况下运行.

The Integration Tests end in ...IntegrationTest.java, and I run the profile that I required (all-tests, integration-tests). The unit tests are run by default.

我很确定我是从某个地方复制过来的,但是现在我不记得链接了.抱歉.

I am pretty sure that I copied this from somewhere, but now I can not remember the link. Sorry.

这篇关于如何使用故障安全插件分别触发集成测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆