maven - 通过maven在Jenkins中构建父pom并运行特定的集成测试?

标签 maven jenkins continuous-integration integration-testing

执行mvn clean install在我的父 pom 上构建所有子模块并运行相关的 junit 测试。它不运行集成测试。

在构建并运行 junit 之后,我想在特定的子模块中运行特定的集成测试。

我正在使用以下命令:

mvn clean install -DTest=integrationTestName

作业失败并显示 No Test Found在构建阶段出错。

我也尝试过使用
mvn clean install -DTest=integrationTestName -pl=sub-module-name

但这只会构建我的具有集成测试的子模块。

问题 : 如何运行某个模块的单个集成测试?

最佳答案

我想你试过 test Maven Surefire 插件的选项(小写)来调用特定测试,Surefire 在 react 堆构建的第一个模块中找不到,因此失败。

我还假设集成测试由 Maven Failsafe Plugin 执行。 .如果没有,他们应该如官方文档所述:

The Failsafe Plugin is designed to run integration tests while the Surefire Plugin is designed to run unit tests. ... If you use the Surefire Plugin for running tests, then when you have a test failure, the build will stop at the integration-test phase and your integration test environment will not have been torn down correctly. .. The Failsafe Plugin will not fail the build during the integration-test phase, thus enabling the post-integration-test phase to execute.



简而言之:这样做更安全、更健壮。

虽然 Maven Failsafe Plugin 的插件配置条目也是 test ,其对应的命令行选项为it.test ,所以你应该运行:
mvn clean install -Dit.test=SampleIT

在哪里 SampleIT是一个集成测试(注意标准 IT 后缀,recognized by default 由 Failsafe 提供。

官方Running a Single Test文档还提供了有关运行单个集成测试的更多详细信息。

另请注意:如果您在构建的其他模块中没有其他集成测试,则上述调用将起作用,否则它将无法更早地找到它(在点击相关模块之前)。

如果您使用 Surefire 运行相关的集成测试(同样,您不应该)或者您有多个模块运行集成测试,那么您应该在相关模块中配置一个配置文件来处理这个特定的调用,例如下列的:
<profiles>
    <profile>
        <id>run-single-it-test</id>
        <activation>
            <property>
                <name>single.it.test</name>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.19.1</version>
                    <configuration>
                        <test>${single.it.test}</test>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>integration-test</goal>
                                <goal>verify</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

然后调用构建如下:
mvn clean install -Dsingle.it.test=SampleIT

因此,Maven 将 activate the profile基于 single.it.test 的值的存在属性并将其传递给 test Failsafe 插件(或 Surefire,如果是这种情况)的属性,Failsafe 将忽略该执行的任何其他集成测试,并且其他模块不会受到任何影响(忽略该属性)。

关于maven - 通过maven在Jenkins中构建父pom并运行特定的集成测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36341830/

相关文章:

java - 如何修复安装 maven jar 插件依赖项时出现的错误?

amazon-web-services - Elastic Beanstalk,Docker和持续集成

node.js - 有没有人使用 Chrome Lighthouse Node CLI 来自动运行审计(尤其是可访问性)?

java - 让 Checkstyle 自定义规则在 Hudson/Jenkins 中工作

java.lang.ClassCastException : org. hibernate.ejb.HibernatePersistence 无法转换为 WebLogic 中的 javax.persistence.spi.PersistenceProvider

open-source - 小型 .NET 开源项目的持续集成

selenium-webdriver - 带有 Selenium 网络驱动程序的 Bamboo

java - 为什么在 JBOSS 上部署 .jar 会出现 :java. lang.NoClassDefFoundError?

maven-shade-plugin - 在类 org.apache.maven.plugins.shade.resource.ManifestResourceTransformer 中找不到 'resource'

java - Maven - 部署静态内容