【问题标题】:Jenkins + selenium tests with failsafe pluginJenkins + selenium 使用故障安全插件进行测试
【发布时间】:2013-02-10 09:13:40
【问题描述】:

我有一个 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

【问题讨论】:

    标签: maven selenium jenkins integration maven-failsafe-plugin


    【解决方案1】:

    根据the documentation

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

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

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

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

    【讨论】:

      【解决方案2】:

      您可以看到 maven 以 SUCCESS 结束。这将使 Jenkins 也取得成功。

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

      希望这会有所帮助。

      【讨论】:

        【解决方案3】:

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

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

        改成

        【讨论】:

          【解决方案4】:

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

          【讨论】:

          • 我的 Jenkins 构建后选择列表中不存在“发布 Junit 报告”选项。
          【解决方案5】:

          正如https://stackoverflow.com/users/709863/stephane-piette 所说: 添加构建后操作“发布性能测试结果报告”。此操作由名为“性能插件”的插件提供。您可能没有安装此插件,这就是它不存在于列表中的原因。

          【讨论】:

            【解决方案6】:

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

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

            【讨论】:

              【解决方案7】:

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

              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-failsafe-plugin</artifactId>
                  ....
                  <configuration>
                      <testFailureIgnore>false</testFailureIgnore>
                  </configuration>
                  <executions>
                      ....
                  </executions>
              </plugin>
              

              【讨论】:

                猜你喜欢
                • 2016-02-15
                • 2013-11-12
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多