首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未检测失败测试的Maven调用程序插件

未检测失败测试的Maven调用程序插件
EN

Stack Overflow用户
提问于 2017-07-04 15:56:05
回答 2查看 1.2K关注 0票数 0

作为根父pom项目的一部分,已经添加了几个集成测试来在示例项目上测试它。

项目文件夹的结构如下:

代码语言:javascript
复制
-root-maven-parent-project
    |- src
    |   |-it
    |      |-sample-project-test1
    |      |-sample-project-test2
    |      |-sample-project-test3
    |      |-settings.xml
    |- pom.xml

主要问题是:尽管sample-project-test2的构建错误地失败了(不应该),但是对于调用程序插件来说,构建是SUCCESSFUL,而且整个构建不会失败。

下面是相关的maven-invoker-plugin配置:

代码语言:javascript
复制
<profile>
    <id>it-tests</id>
    <build>
        <plugins>
            <!-- Integration tests configuration -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-invoker-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <streamLogs>true</streamLogs>
                    <goals>
                        <goal>clean</goal>
                        <goal>generate-sources</goal>
                    </goals>
                    <settingsFile>src/it/settings.xml</settingsFile>
                    <failIfNoProjects>true</failIfNoProjects>
                </configuration>
                <executions>
                    <execution>
                        <id>integration-test-release</id>
                        <goals>
                            <goal>install</goal>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                        <configuration>
                            <cloneProjectsTo>${project.build.directory}/its/sample-project-test1</cloneProjectsTo>
                            <pom>src/it/sample-project-test1/pom.xml</pom>
                            <properties>
                                <scmBranch>release-something</scmBranch>
                            </properties>
                        </configuration>
                    </execution>
                    <execution>
                        <id>integration-test-hotfix</id>
                        <goals>
                            <goal>install</goal>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                        <configuration>
                            <cloneProjectsTo>${project.build.directory}/its/sample-project-test2</cloneProjectsTo>
                            <pom>src/it/sample-project-test2/pom.xml</pom>
                            <properties>
                                <scmBranch>hotfix-something</scmBranch>
                            </properties>
                        </configuration>
                    </execution>
                    <execution>
                        <id>integration-test-master</id>
                        <goals>
                            <goal>install</goal>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                        <configuration>
                            <cloneProjectsTo>${project.build.directory}/its/sample-project-test3</cloneProjectsTo>
                            <pom>src/it/sample-project-test3/pom.xml</pom>
                            <properties>
                                <scmBranch>master</scmBranch>
                            </properties>
                        </configuration>
                    </execution>
            </plugin>
        </plugins>
    </build>
</profile>

如您所见,配置了多个执行,因为每个执行都需要自己的属性。每个执行都指向自己的集成测试项目和pom。

对于特定的执行,构建显然是失败的:

代码语言:javascript
复制
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] BUILD FAILURE
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Total time: 2.337 s
[INFO] [INFO] Finished at: 2017-07-04T17:35:49+02:00
[INFO] [INFO] Final Memory: 12M/220M
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.4.1:enforce (enforce-snapshot-management) on project cmp-sample-project-test2: Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed. -> [Help 1]
[INFO] [ERROR] 
[INFO] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[INFO] [ERROR] Re-run Maven using the -X switch to enable full debug logging.
[INFO] [ERROR] 
[INFO] [ERROR] For more information about the errors and possible solutions, please read the following articles:
[INFO] [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[INFO]           pom.xml .......................................... FAILED (4.1 s)
[INFO]   The build exited with code 1. See C:\data\git-repositories\root-maven-parent\target\its\sample-project-test2\build.log for details.

但是,在构建的底部,我们看到maven-invoker-pluginmaven-invoker-plugin目标聚合了结果,将相关的测试标记为Passed,并生成了SUCCESS

代码语言:javascript
复制
[INFO] 
[INFO] --- maven-invoker-plugin:3.0.0:verify (integration-test-release) @ root-maven-parent ---
[INFO] -------------------------------------------------
[INFO] Build Summary:
[INFO]   Passed: 1, Failed: 0, Errors: 0, Skipped: 0
[INFO] -------------------------------------------------
[INFO] 
[INFO] --- maven-invoker-plugin:3.0.0:verify (integration-test-hotfix) @ root-maven-parent ---
[INFO] -------------------------------------------------
[INFO] Build Summary:
[INFO]   Passed: 1, Failed: 0, Errors: 0, Skipped: 0
[INFO] -------------------------------------------------
[INFO] 
[INFO] --- maven-invoker-plugin:3.0.0:verify (integration-test-master) @ root-maven-parent ---
[INFO] -------------------------------------------------
[INFO] Build Summary:
[INFO]   Passed: 1, Failed: 0, Errors: 0, Skipped: 0
[INFO] -------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

此外,仅从命令行运行失败的测试,如下所示:

代码语言:javascript
复制
mvn invoker:integration-test@integration-test-hotfix invoker:verify -Pit-tests

测试项目的子构建失败,输出在测试摘要中被正确标记为Failed,并且生成正确地以FAILURE结束。

问题:为什么在使用maven-invoker-plugin执行多个集成测试时,虽然测试失败了,但在测试摘要中将测试标记为Passed,而构建没有失败,而只运行隔离测试--一切都失败了?

注意:不使用调用程序属性文件

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-07-05 14:53:10

问题用以下解释解决了,尽管我认为插件的行为可以改进一些东西(见下文)。

整个maven-invoker-plugin简化为以下配置:

代码语言:javascript
复制
<profile>
    <id>it-tests</id>
    <build>
        <plugins>
            <!-- Integration tests configuration -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-invoker-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <streamLogs>true</streamLogs>
                    <goals>
                        <goal>clean</goal>
                        <goal>generate-sources</goal>
                    </goals>
                    <settingsFile>src/it/settings.xml</settingsFile>
                    <failIfNoProjects>true</failIfNoProjects>
                    <cloneProjectsTo>${project.build.directory}/its</cloneProjectsTo>
                </configuration>
                <executions>
                    <execution>
                        <id>integration-test-release</id>
                        <goals>
                            <goal>install</goal>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>

基本上:只有一个插件的执行,而不是每个测试的执行,这确实是冗长和不可伸缩的,但是由于在每个集成测试中需要对相同的属性有不同的值而被迫执行。显然,通过pom配置是不可能的,只有通过test.properties文件才能实现--除非我没有弄错。因此,作为对上述配置的补充,我在每个集成测试项目文件夹中添加了一个test.properties文件,内容如下:

代码语言:javascript
复制
scmBranch=master

事实上替换pom.xml文件中的内容(作为执行maven-invoker-plugin的一部分)

代码语言:javascript
复制
<properties>
    <scmBranch>master</scmBranch>
</properties>

这种机制(每个测试文件夹只执行插件+测试属性文件)修复了这个问题,允许构建具有相同属性的不同值的多个集成测试。希望此解决方案有助于解决类似问题。

以下是构建的最终结果--正确地聚合测试并有效地尊重它们的子构建输出(而在构建之前,每次生成6 Build Summary of Passed: 1,尽管不正确)。

代码语言:javascript
复制
[INFO] --- maven-invoker-plugin:3.0.0:verify (pom-integration-test) @ root-maven-parent ---
[INFO] -------------------------------------------------
[INFO] Build Summary:
[INFO]   Passed: 6, Failed: 0, Errors: 0, Skipped: 0
[INFO] -------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

然而,仍然存在一些问题,

  • 在不使用test.properties文件的情况下,如何通过pom.xml配置实现相同的配置?通常,这只能是一种替代办法,而不是强制性的,也是唯一可能的解决办法。这就是为什么这是一个不完全的特性(一个bug?)对我来说。
  • 插件的多次执行会导致构建结束时的测试摘要正确地遵循执行顺序,测试执行的次数(在这种情况下,每次执行总是1次),但显然没有反映每个子构建的有效结果。为什么?这可能是由于插件的意外使用而导致的错误或错误行为。
票数 1
EN

Stack Overflow用户

发布于 2017-07-04 17:07:27

使用此配置:-

代码语言:javascript
复制
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>1.0</version>
        <configuration>
            <rules>
                <banDuplicateClasses>
                    <findAllDuplicates>true</findAllDuplicates>
                </banDuplicateClasses>
            </rules>
            <fail>false</fail>
        </configuration>
        <dependencies>
            <dependency>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>extra-enforcer-rules</artifactId>
                <version>1.0-alpha-1</version>
            </dependency>
        </dependencies>
    </plugin>

有关更多信息,请参阅此链接:

http://maven.apache.org/enforcer/maven-enforcer-plugin/

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44910155

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档