1

How to rerun failed test cases of cucumber-jvm in jenkins?

According to answers mentioned in this thread: How to rerun failed test cases in cucumber-jvm?

There is different maven command to move and run scenarios for rerun.txt. How to execute them in Jenkins with separate maven command for rerun?

Kpras
  • 163
  • 2
  • 2
  • 10
  • Have you seen this: https://maven.apache.org/surefire/maven-failsafe-plugin/examples/rerun-failing-tests.html#Re-run_execution_in_Cucumber_JVM – SiKing Dec 16 '19 at 21:23
  • This is not working some how. Also I have failures in rerun.text for which I need to use separate maven command. – Kpras Dec 17 '19 at 22:02
  • I don't know anything about `rerun.text`, but that plugin works perfectly fine for me. Just thought I would offer it as an option. – SiKing Dec 17 '19 at 23:18
  • Did you implement for cucumber? – Kpras Dec 19 '19 at 00:51

2 Answers2

1

I use framework, which uses in the background to run everything. Here are the relevant parts of my pom.

I have everything in a separate project, not mixed with any other code. If this is not your case, the following might break your build!

I turn off unit tests:

    <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>

This does not relate to your question, but I manage all my browser drivers with:

                    <!-- 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>

I use the failsafe-plugin to run my integration tests:

                    <!-- 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>

The above will not rerun any failed tests, which is what you probably want when you run stuff locally on your machine.

On Jenkins only, I turn on the rerunning of failed tests:

    <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>
SiKing
  • 10,003
  • 10
  • 39
  • 90
  • In surefire plugin also we have this option - mvn -Dsurefire.rerunFailingTestsCount=2 test Between how it knows that you have to run only failed test cases? Cucumber either picks feature file or we have to post failures in rerun.txt and feed it to runner. – Kpras Jan 29 '20 at 20:21
  • @Kpras AFAIK no intermediary (such as rerun.txt) is used. You could look through the source to see exactly how this is accomplished https://github.com/apache/maven-surefire/tree/master/surefire-providers/surefire-junit47 – SiKing Jan 29 '20 at 21:22
0

I pasted the following in my Pom.xml file and I do not see any failed test case rerunning in Jenkins. Can you explain how to configure this Jenkins please

<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>
Vinay
  • 1