2

我有一个 Jenkins 平台,它调用 maven 来进行单元测试(使用 surefire 插件)和集成测试(使用故障安全插件)。当集成测试出现错误时,Jenkins 认为构建成功。这种行为正常吗?我希望它认为构建不稳定。更一般地说,您知道 Jenkins 如何读取和解释构建结果以将构建视为成功或不稳定吗?我在网上某处读到故障安全报告必须重定向到万无一失的报告路径。我做了id,但问题仍然存在。

pom.xml:

[...]
    <plugin>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.10</version>
      <configuration>
        <disableXmlReport>false</disableXmlReport>
      </configuration>
      <executions>
        <execution>
          <id>default-test</id>
          <phase>test</phase>
          <configuration>
            <includes>
              <include>**/tests/**</include>
            </includes>
            <excludes>
              <exclude>**/testsIntegration/**</exclude>
            </excludes>
          </configuration>
        </execution>
      </executions>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-failsafe-plugin</artifactId>
      <version>2.7.2</version>
      <configuration>
        <disableXmlReport>false</disableXmlReport>
        <reportsDirectory>${basedir}/target/surefire-reports</reportsDirectory>
        <includes>
          <include>com/acelys/conventionsJuridiques/*.java</include>
          <!-- ... inclure les tests Selenium  -->
        </includes>
      </configuration>
      <executions>
        <execution>
          <id>integration-test</id>
          <phase>integration-test</phase>
          <goals>
            <goal>integration-test</goal>
          </goals>
          <configuration>
            <includes>
              <include>**/testsIntegration/**</include>
            </includes>
            <excludes>
              <exclude>**/tests/**</exclude>
            </excludes>
          </configuration>
        </execution>
      </executions>
    </plugin> 
[...]

詹金斯的输出:

[...]
mojoStarted org.apache.maven.plugins:maven-failsafe-plugin:2.7.2(integration-test)
[INFO] 
[INFO] --- maven-failsafe-plugin:2.7.2:integration-test (integration-test) @ BaseContrats ---
[INFO] Failsafe report directory: C:\jenkins_home\workspace\Base Contrats EXT JS MAVEN\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.acelys.conventionsJuridiques.testsIntegration.connexion.TestConnexion

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 23.971 sec <<< FAILURE!

Results :

Failed tests: 
  testHomePage(com.acelys.conventionsJuridiques.testsIntegration.connexion.TestConnexion)

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0

[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
mojoSucceeded org.apache.maven.plugins:maven-failsafe-plugin:2.7.2(integration-test)
mojoStarted org.apache.tomcat.maven:tomcat6-maven-plugin:2.1-SNAPSHOT(tomcat-shutdown)
[INFO] 
[INFO] --- tomcat6-maven-plugin:2.1-SNAPSHOT:shutdown (tomcat-shutdown) @ BaseContrats ---
25 févr. 2013 09:32:08 org.apache.coyote.http11.Http11Protocol destroy
INFO: Stopping Coyote HTTP/1.1 on http-8080
25 févr. 2013 09:32:08 org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
25 févr. 2013 09:32:08 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc

mojoSucceeded org.apache.tomcat.maven:tomcat6-maven-plugin:2.1-SNAPSHOT(tomcat-shutdown)
projectSucceeded BaseContrats:BaseContrats:1.0-SNAPSHOT
sessionEnded
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2:07.408s
[INFO] Finished at: Mon Feb 25 09:32:08 CET 2013
[INFO] Final Memory: 13M/51M
[INFO] ------------------------------------------------------------------------
Projects to build: [MavenProject: BaseContrats:BaseContrats:1.0-SNAPSHOT @ C:\jenkins_home\workspace\Base Contrats EXT JS MAVEN\pom.xml]
[JENKINS] Archiving C:\jenkins_home\workspace\Base Contrats EXT JS MAVEN\pom.xml to C:\jenkins_home\jobs\Base Contrats EXT JS MAVEN\modules\BaseContrats$BaseContrats\builds\2013-02-25_09-29-58\archive\BaseContrats\BaseContrats\1.0-SNAPSHOT\BaseContrats-1.0-SNAPSHOT.pom
[JENKINS] Archiving C:\jenkins_home\workspace\Base Contrats EXT JS MAVEN\target\ConventionsJuridiques.war to C:\jenkins_home\jobs\Base Contrats EXT JS MAVEN\modules\BaseContrats$BaseContrats\builds\2013-02-25_09-29-58\archive\BaseContrats\BaseContrats\1.0-SNAPSHOT\BaseContrats-1.0-SNAPSHOT.war
channel stopped
Finished: SUCCESS
4

7 回答 7

2

根据文档

failsafe:verify 验证应用程序的集成测试是否通过。

您需要将目标添加到 maven-failsafe-plugin 执行中:

<goals>
   <goal>integration-test</goal>
   <goal>verify</goal>
</goals>

这将允许 Jenkins 解释测试结果并将构建标记为不稳定。

于 2013-10-22T15:16:28.410 回答
1

您可以看到 maven 以 SUCCESS 完成。这将使詹金斯也取得成功。

要将构建标记为不稳定,您需要一个构建后操作来分析您的测试结果并将构建标记为失败或不稳定。我建议您搜索有关 Jenkins 构建后操作的更多详细信息,以处理测试结果并根据需要标记构建。

希望这可以帮助。

于 2013-02-25T09:24:27.077 回答
1

在构建后操作下,发布 JUnit 测试结果报告会更改要搜索的报告 XML。

假设是使用标准的万无一失和故障安全插件输出目录。

在此处输入图像描述

更改为

在此处输入图像描述

于 2016-04-14T01:13:11.243 回答
0

As said by https://stackoverflow.com/users/709863/stephane-piette: Add a post build action 'Publish Performance test result report'. This action is provided by the plugin named 'Performance plugin'. You probably do not have this plugin installed, which is why it does not exist in the list.

于 2013-04-23T14:23:30.867 回答
0

您应该在构建中添加一个步骤:“发布 Junit 报告”您将获得显示所有测试结果的图表,但如果测试失败,它也会设置正确的构建结果。

于 2013-02-25T11:16:17.857 回答
0

当测试失败时,故障安全插件的目标“集成测试”不会将构建标记为错误。

您必须在插件执行中添加目标“验证”以在“集成测试”之后运行。这将查找错误或失败并将构建标记为“错误”。然后 Jenkins 会看到 Maven 没有成功。

于 2016-11-18T13:44:21.033 回答
0

您必须设置插件的配置,以便在测试失败时构建失败:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    ....
    <configuration>
        <testFailureIgnore>false</testFailureIgnore>
    </configuration>
    <executions>
        ....
    </executions>
</plugin>
于 2019-09-12T15:34:26.657 回答