Jenkins + selenium测试使用故障安全插件

时间:2013-02-25 09:05:05

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

我有一个Jenkins平台,它调用maven进行单元测试(使用surefire插件)和集成测试(使用failsafe插件)。当集成测试中出现错误时,Jenkins认为构建成功。这种行为是否正常?我更喜欢它认为构建不稳定。更一般地说,你知道Jenkins如何阅读和解释构建的结果,以将构建视为成功或不稳定吗?我在网上的某处读到,必须将故障安全报告重定向到surefire报告路径。我做了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> 
[...]

jenkins的输出:

[...]
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

7 个答案:

答案 0 :(得分:2)

根据the documentation

  

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

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

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

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

答案 1 :(得分:1)

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

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

希望这有帮助。

答案 2 :(得分:0)

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

答案 3 :(得分:0)

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

答案 4 :(得分:0)

在发布后操作下,Publish JUnit测试结果报告会更改报告XML以进行搜索。

假设是使用标准的surefire和failsafe插件输出目录。

enter image description here

更改为

enter image description here

答案 5 :(得分:0)

目标&#34;整合测试&#34;当测试失败时,故障安全插件不会将构建标记为错误。

你必须添加目标&#34;验证&#34;在&#34;整合测试&#34;之后运行在插件执行中。这将查找错误或失败,并将构建标记为&#34;错误&#34;。然后Jenkins会看到Maven没有成功。

答案 6 :(得分:0)

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

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