8

我们在这里有一个持续的需求,我不知道如何使用库存的 Maven 2 工具和文档来解决。

我们的一些开发人员有一些运行时间很长的 JUnit 测试(通常是压力测试),在任何情况下都不应该作为构建过程/夜间构建的常规部分运行。

当然,我们可以使用 surefire 插件的排除机制并将它们从构建中剔除,但理想情况下,我们希望开发人员可以通过 Maven 2 随意运行它们。

4

4 回答 4

12

通常,您会将配置文件添加到运行不同测试集的 maven 配置中:

使用 mvn -Pintegrationtest install 运行它

    <profile>
        <id>integrationtest</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <argLine>-client -Xmx896m -XX:MaxPermSize=192m</argLine>
                        <forkMode>once</forkMode>
                        <includes>
                            <include>**/**/*Test.java</include>
                            <include>**/**/*IntTest.java</include>
                        </includes>
                        <excludes>
                            <exclude>**/**/*SeleniumTest.java</exclude>
                        </excludes>
                    </configuration>
                </plugin>
            </plugins>
        </build>
        <activation>
            <property>
                <name>integrationtest</name>
            </property>
        </activation>
    </profile>
于 2008-10-30T21:00:13.290 回答
4

添加到krosenvold的答案中,为确保没有意外行为,请确保您还有一个默认情况下处于活动状态的默认配置文件,其中不包括您要在特殊配置文件中运行的集成或压力测试。

<profile>
    <id>normal</id>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>**/**/*IntTest.java</exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
</profile>

您将需要像这样创建一个配置文件,只需在配置文件之外列出surefire插件将覆盖配置文件,如果它被选择:

mvn -P integrationtest clean install
于 2011-09-06T19:54:47.457 回答
1

使用诸如Super Helpful Integration Test Thingy之类的集成测试插件将集成测试(长时间运行的、系统的)与单元测试分开(纯粹主义者说所有真正的单元测试最多运行 30 秒)。为您的单元测试和集成测试制作两个 Java 包。

然后不要将此插件绑定到阶段(正常的 maven 生命周期),并且仅在它被显式调用为目标时运行它,如下所示: mvn shitty:clean shitty:install shitty:test

<plugins>
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>shitty-maven-plugin</artifactId>
  </plugin>
</plugins>

这样,您的普通开发人员不会受到影响,并且您将能够按需运行集成测试。

于 2009-02-14T21:27:14.097 回答
0

另一种选择是让压力测试检测它是否在 Maven 中运行并且只运行一次或两次。即变成一个常规的功能测试。这样可以检查代码还是不错的,但是运行时间长了。

于 2009-02-15T07:29:18.283 回答