如何使用failsafe-plugin单独解决集成测试?

时间:2014-12-01 23:27:49

标签: java maven maven-surefire-plugin

我无法运行集成测试,只能运行单元测试。

这是我的Maven配置(请参阅下面的代码)。它使用两个插件。其中一个是maven-failsafe-plugin,第二个是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>

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

mvn clean test

还有命令单独启动集成测试

mvn clean failsafe:integration-test verify

调用最后一个命令的结果是

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

1 个答案:

答案 0 :(得分:0)

我使用配置文件:

属性

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

行家-万无一失-插件

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

行家故障安全-插件

        <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结束,我运行我需要的配置文件(所有测试,集成测试)。单位测试默认运行。

我很确定我是从某个地方复制过的,但现在我记不清了这个链接了。遗憾。