【问题标题】:How rerun failed test cases of cucumber-jvm in jenkins如何在 jenkins 中重新运行 cucumber-jvm 失败的测试用例
【发布时间】:2019-12-16 21:11:30
【问题描述】:

如何在jenkins中重新运行cucumber-jvm失败的测试用例?

根据这个帖子中提到的答案: How to rerun failed test cases in cucumber-jvm?

rerun.txt 有不同的 maven 命令来移动和运行场景。如何在 Jenkins 中使用单独的 maven 命令执行它们以重新运行?

【问题讨论】:

  • 这在某种程度上不起作用。我也有 rerun.text 失败,我需要使用单独的 maven 命令。
  • 我对@9​​87654323@一无所知,但该插件对我来说非常好用。只是想我会提供它作为一个选项。
  • 你为黄瓜实现了吗?

标签: maven jenkins cucumber jenkins-pipeline cucumber-jvm


【解决方案1】:

我使用 框架,它在后台使用 来运行一切。这是我的 pom 的相关部分。

我将所有内容都放在一个单独的项目中,没有与任何其他代码混合。如果这不是您的情况,以下可能会破坏您的构建!

我关闭了单元测试:

    <build>
            <plugins>
                    <!-- no unit tests: skip anything named *Test -->
                    <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-surefire-plugin</artifactId>
                            <version>${surefire.plugin.version}</version>
                            <configuration>
                                    <skipTests>true</skipTests>
                            </configuration>
                    </plugin>

这与您的问题无关,但我通过以下方式管理我的所有 浏览器驱动程序:

                    <!-- docs: https://ardesco.lazerycode.com/testing/webdriver/2012/08/12/introducing-the-driver-binary-downloader-maven-plugin-for-selenium.html -->
                    <plugin>
                            <groupId>com.lazerycode.selenium</groupId>
                            <artifactId>driver-binary-downloader-maven-plugin</artifactId>
                            <version>${driver-binary-downloader.plugin.version}</version>
                            <configuration>
                                    <rootStandaloneServerDirectory>${project.basedir}/selenium/bin</rootStandaloneServerDirectory>
                                    <downloadedZipFileDirectory>${project.basedir}/selenium/zip</downloadedZipFileDirectory>
                                    <customRepositoryMap>${project.basedir}/RepositoryMap.xml</customRepositoryMap>
                                    <overwriteFilesThatExist>true</overwriteFilesThatExist>
                            </configuration>
                            <executions>
                                    <execution>
                                            <phase>pre-integration-test</phase>
                                            <goals>
                                                    <goal>selenium</goal>
                                            </goals>
                                    </execution>
                            </executions>
                    </plugin>

我使用failsafe-plugin 运行我的集成测试:

                    <!-- integration tests: run everything named *IT -->
                    <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-failsafe-plugin</artifactId>
                            <version>${surefire.plugin.version}</version>
                            <configuration>
                                    <systemPropertyVariables>
                                            <!-- set by driver-binary-downloader-maven-plugin -->
                                            <webdriver.chrome.driver>${webdriver.chrome.driver}</webdriver.chrome.driver>
                                            <webdriver.gecko.driver>${webdriver.gecko.driver}</webdriver.gecko.driver>
                                    </systemPropertyVariables>
                            </configuration>
                            <executions>
                                    <execution>
                                            <goals>
                                                    <goal>integration-test</goal>
                                                    <goal>verify</goal>
                                            </goals>
                                    </execution>
                            </executions>
                    </plugin>
            </plugins>
    </build>

以上内容将不会重新运行任何失败的测试,这可能是您在机器上本地运行东西时想要的。

仅在 Jenkins 上,我打开失败测试的重新运行:

    <profiles>
            <profile>
                    <id>jenkins</id>
                    <activation>
                            <property>
                                    <name>env.JENKINS_HOME</name>
                            </property>
                    </activation>
                    <build>
                            <plugins>
                                    <plugin>
                                            <artifactId>maven-failsafe-plugin</artifactId>
                                            <dependencies>
                                                    <!-- docs: https://maven.apache.org/surefire/maven-failsafe-plugin/examples/rerun-failing-tests.html#Re-run_execution_in_Cucumber_JVM -->
                                                    <dependency>
                                                            <groupId>org.apache.maven.surefire</groupId>
                                                            <artifactId>surefire-junit47</artifactId>
                                                            <version>${surefire.plugin.version}</version>
                                                    </dependency>
                                            </dependencies>
                                            <configuration>
                                                    <rerunFailingTestsCount>2</rerunFailingTestsCount>
                                            </configuration>
                                    </plugin>
                            </plugins>
                    </build>
            </profile>
    </profiles>

【讨论】:

  • 在surefire插件中我们也有这个选项 - mvn -Dsurefire.rerunFailingTestsCount=2 test 它怎么知道你必须只运行失败的测试用例? Cucumber 要么选择功能文件,要么我们必须在 rerun.txt 中发布失败并将其提供给 runner。
  • @Kpras AFAIK 没有使用中介(例如 rerun.txt)。您可以查看源代码以确切了解这是如何完成的github.com/apache/maven-surefire/tree/master/surefire-providers/…
【解决方案2】:

我在我的 Pom.xml 文件中粘贴了以下内容,我没有看到任何失败的测试用例在 Jenkins 中重新运行。你能解释一下如何配置这个Jenkins吗

<profiles>
        <profile>
            <id>jenkins</id>
            <activation>
                <property>
                    <name>env.JENKINS_HOME</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <dependencies>
                            <!-- docs: https://maven.apache.org/surefire/maven-failsafe-plugin/examples/rerun-failing-tests.html#Re-run_execution_in_Cucumber_JVM -->
                            <dependency>
                                <groupId>org.apache.maven.surefire</groupId>
                                <artifactId>surefire-junit47</artifactId>
                                <version>2.22.2</version>
                            </dependency>
                        </dependencies>
                        <configuration>
                            <rerunFailingTestsCount>2</rerunFailingTestsCount>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

【讨论】:

    最近更新 更多