Skip to content

Commit

Permalink
fix "rerun failing tests" Maven features if multiple test cases failed (
Browse files Browse the repository at this point in the history
#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]>
  • Loading branch information
aaschmid committed Sep 14, 2018
1 parent 2d2d266 commit 918878e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ subprojects {
apply plugin: 'osgi'

group = 'com.tngtech.junit.dataprovider'
version = '2.3'
version = '2.4-SNAPSHOT'

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ public DataProviderFilter(Filter filter) {

@Override
public boolean shouldRun(Description description) {
Matcher filterDescriptionMatcher = DESCRIPTION_PATTERN.matcher(filter.describe());
if (!filterDescriptionMatcher.find()) {
String filterDescription = filter.describe();

Matcher filterDescriptionMatcher = DESCRIPTION_PATTERN.matcher(filterDescription);
if (filterDescription.contains(" OR ") || !filterDescriptionMatcher.find()) {
return filter.shouldRun(description);
}
String methodName = filterDescriptionMatcher.group(GROUP_METHOD_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ public void testShouldRunShouldCallOriginalFilterShouldRunIfIsTestAndGivenDescri
verifyNoMoreInteractions(filter);
}

@Test
public void testShouldRunShouldCallOriginalFilterShouldRunIfGivenDescriptionContainsOr() {
// Given:
doReturn("Matching description Method failing1[0: 0](Test1) OR Method failing2[0: 0](Test2)").when(filter)
.describe();
Description description = setupDescription(true, "failing1[0: 0](Test1)");

// When:
underTest.shouldRun(description);

// Then:
verify(filter).describe();
verify(filter).shouldRun(description);
verifyNoMoreInteractions(filter);
}

@Test
public void testShouldRunShouldReturnFalseWhenDescriptionDoesNotHaveExpectedMethodName() {
// Given:
Expand Down

0 comments on commit 918878e

Please sign in to comment.