Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataProviderRunner.class do not use rerunFailingTestsCount in parallel #113

Closed
emaks opened this issue Aug 17, 2018 · 8 comments
Closed

Comments

@emaks
Copy link

emaks commented Aug 17, 2018

Maven version 3.5.4

I have maven project with next pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>test</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
        <dependency>
            <groupId>com.tngtech.junit.dataprovider</groupId>
            <artifactId>junit4-dataprovider</artifactId>
            <version>2.3</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.0</version>
                <configuration>
                    <rerunFailingTestsCount>1</rerunFailingTestsCount>
                    <parallel>classes</parallel>
                    <useUnlimitedThreads>false</useUnlimitedThreads>
                    <perCoreThreadCount>false</perCoreThreadCount>
                    <threadCount>2</threadCount>
                    <rerunFailingTestsCount>1</rerunFailingTestsCount>
                    <includes>
                        <include>Test1.class</include>
                        <include>Test2.class</include>
                    </includes>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

And 2 test classes

import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(DataProviderRunner.class)
public class Test1 {
    private static int value = 0;

    @DataProvider
    public static Object[][] dataProviderAdd() {
        return new Object[][]{
            {0},
        };
    }

    @Test
    @UseDataProvider("dataProviderAdd")
    public void failing1(int value11) {
        if (value != 0) {
            System.out.println("SUCCESS");
            Assert.assertTrue(true);
        } else {
            System.out.println("FAIL");
            value = 1;
            Assert.assertTrue(false);
        }
    }
}

and

import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(DataProviderRunner.class)
public class Test2 {
    private static int value = 0;

    @DataProvider
    public static Object[][] dataProviderAdd() {
        return new Object[][]{
            {0},
        };
    }

    @Test
    @UseDataProvider("dataProviderAdd")
    public void failing2(int value11) {
        if (value != 0) {
            System.out.println("SUCCESS");
            Assert.assertTrue(true);
        } else {
            System.out.println("FAIL");
            value = 1;
            Assert.assertTrue(false);
        }
    }
}

Actual result

If I run mvn test tests will be executed without re-run and fail

Expected result

Tests will pass(with re-run)

Note

If I change

                    <includes>
                        <include>Test1.class</include>
                        <include>Test2.class</include>
                    </includes>

on

                    <includes>
                        <include>Test1.class</include>
                    </includes>

Test will pass

@aaschmid
Copy link
Member

aaschmid commented Aug 23, 2018

Puh ... I at least identified the problem:

  • Maven uses a special MatchDescriptions Filter for rerunning failed test cases.
  • This causes that junit-dataprovider is not able to filter the tests to executed correctly.
  • Therefore no test are executed for the second run.

junit-dataprovider relays on the filter description but the one from MatchDescriptions cannot be parsed for now. It contains a not recognized "OR":

failing1[0: 0](Test1) OR Method failing2[0: 0](Test2)

Having only a single failed test case, though, the filter description does not contain an "OR" and works correctly.

@emaks
Copy link
Author

emaks commented Sep 11, 2018

@aaschmid Is the any plans when you could fix this issue?

@aaschmid
Copy link
Member

@emaks: there is but I was and I am a bit busy with some complex private issue ...

How urgent is it for you? Sounds like you have a lot blinking test cases, do you?

@emaks
Copy link
Author

emaks commented Sep 11, 2018

@aaschmid
unfortunately, yes I do. I use this approach for selenium tests which are testing application with a lot of 3rd-party integrations. Those integrations are unstable and at that moment only one possible solution for this situation - re-run failed tests

@aaschmid
Copy link
Member

aaschmid commented Sep 14, 2018

Understood. Can you try version "2.4-SNAPSHOT" which I just created and uploaded to Maven Central Snapshop Repository?

        <dependency>
            <groupId>com.tngtech.junit.dataprovider</groupId>
            <artifactId>junit4-dataprovider</artifactId>
            <version>2.4-SNAPSHOT</version>
        </dependency>

@emaks
Copy link
Author

emaks commented Sep 17, 2018

works as expected with this version

aaschmid added a commit that referenced this issue Sep 23, 2018
#113)

Maven create a custom filter containing one or more valid test cases to
run. For one test case this works but for multiple test cases the
filter description contains an "OR". If this "OR" is found, the filter
request needs to be forwarded to the original `filter.shouldRun(...)`.

Signed-off-by: Andreas Schmid <[email protected]>
@aaschmid
Copy link
Member

Thanks for the feedback. I will release version 2.4 as soon as oss.sonatype.org is available again.

@aaschmid
Copy link
Member

Release is done and will appear on MavenCentral within the next hours, thanks @emaks for the feedback.

aaschmid added a commit to aaschmid/junit-dataprovider that referenced this issue Jul 26, 2019
* upstream/master: (129 commits)
  add license header to every delivered file
  Update README.md
  Update and rename LICENSE.md to LICENSE
  downgrade wrapper due to TNG#119
  next SNAPSHOT version 2.7
  prepare next release version
  fix compatibility with 5.5.0 and above (TNG#118)
  Create SECURITY.md
  add more JDKs to run travis CI against
  prepare next release version v2.5
  fix compatibility issue with new junit-jupiter version 5.4.* (TNG#118)
  remove no longer required workaround as junit-jupiter compatibility is now >= 5.4.0 anyway
  upgrade gradle-cpd-plugin to latest
  upgrade to new gradle-cpd-plugin version 1.3
  replace ' with "
  upgrade Gradle wrapper to 5.1.1
  upgrade Gradle wrapper to 5.0
  prepare v2.4
  fix "rerun failing tests" Maven features if multiple test cases failed (TNG#113)
  add rules acceptance test for junit4/ (TNG#22)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants