1

我已经将 Cargo 设置为在 Maven 配置文件中的预集成测试阶段启动 glassfish 的实例。然后我的测试在集成测试阶段运行,最后,cargo 在集成测试后阶段关闭 tomcat 实例。

当所有测试都通过时,这很好用,但是如果任何测试失败,maven 构建就会失败,并且似乎永远不会达到 post-integration-test 阶段,这会使 glassfish 实例运行(我无法在不杀死它的情况下停止它过程)。

难道我做错了什么?有没有办法确保货物关闭我的 glassfish 实例,即使集成测试阶段失败?

我的行家简介:

<profile>
    <!-- run integration tests against the app deployed to a container -->
    <id>integration</id>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <!-- override the exclusion and include integration tests -->
                            <excludes>
                                <exclude>none</exclude>
                            </excludes>
                            <includes>
                                <include>***IntegrationTest.java</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <version>${cargo.plugin.version}</version>
                <executions>
                    <execution>
                        <id>start-server</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop-server</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <container>
                        <containerId>glassfish3x</containerId>
                        <artifactInstaller>
                            <groupId>org.glassfish.main.distributions</groupId>
                            <artifactId>glassfish</artifactId>
                            <version>${glassfish.version}</version>
                        </artifactInstaller>
                    </container>
                    <configuration>
                        <properties>
                            <cargo.datasource.datasource.mysql>
                                cargo.datasource.jndi=jdbc/TrackerPool|
                                cargo.datasource.driver=com.mysql.jdbc.Driver|
                                cargo.datasource.url=jdbc:mysql://localhost/[database]|
                                cargo.datasource.transactionsupport=LOCAL_TRANSACTION|
                                cargo.datasource.username=[username]|
                                cargo.datasource.password=[password]
                            </cargo.datasource.datasource.mysql>
                        </properties>
                    </configuration>
                </configuration>
            </plugin>
        </plugins>
    </build>
</profile>
4

1 回答 1

2

问题只是基于 maven-surefire-plugin 的错误使用,该插件旨在与单元测试相关,但不适用于集成测试。为此,存在maven-failsave-plugin可以解决您的问题。

maven-failsave-plugin 的使用使您无需为集成测试定义包含规则。Maven 中用于集成测试的通常命名约定是这样的:

 IT*.java
 *IT.java
 *ITCase.java

所以我建议相应地命名你的集成测试,这样你就不需要任何类型的排除/包含规则,既不需要 maven-surefire-plugin (单元测试)也不需要 maven-failsafe-plugin (集成测试)。

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.13</version>
    <executions>
        <execution>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
</plugin>

仅当您希望在集成测试失败的情况下使构建失败时才需要验证目标。你必须像这样调用maven:

mvn -Pprofile clean verify 
于 2013-01-12T17:59:47.630 回答