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

时间:2019-12-16 21:11:30

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

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

根据此主题中提到的答案: How to rerun failed test cases in cucumber-jvm?

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

2 个答案:

答案 0 :(得分:0)

我使用框架,该框架在后台使用来运行所有内容。这是我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>

答案 1 :(得分:0)

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

var blob;

var blobs = [];
var zoom = 1;

function setup() {
  createCanvas(600, 600);
  blob = new Blob(0, 0, 64);
  for (var i = 0; i < 200; i++) {
    var x = random(-width, width);
    var y = random(-height, height);
    blobs[i] = new Blob(x, y, 2);
  }
}

function draw() {
  background(0);

  translate(width / 2, height / 2);
  var newzoom = 64 / blob.r;
  zoom = lerp(zoom, newzoom, 0.1);
  scale(zoom);
  translate(-blob.pos.x, -blob.pos.y);

  for (var i = blobs.length - 1; i >= 0; i--) {
    blobs[i].show();
    if (blob.eats(blobs[i])) {
      blobs.splice(i, 1);
    }
  }

  blob.show();
  blob.update();
}