Skip to content

Commit

Permalink
fix falky test results categories matching
Browse files Browse the repository at this point in the history
  • Loading branch information
baev committed Nov 6, 2024
1 parent 02e2f50 commit 076f33d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -161,7 +162,8 @@ public static boolean matches(final TestResult result, final Category category)
final boolean matchesTrace = isNull(category.getTraceRegex())
|| nonNull(result.getStatusTrace())
&& matches(result.getStatusTrace(), category.getTraceRegex());
final boolean matchesFlaky = result.isFlaky() == category.isFlaky();
final boolean matchesFlaky = Objects.isNull(category.getFlaky())
|| result.isFlaky() == category.getFlaky();
return matchesStatus && matchesMessage && matchesTrace && matchesFlaky;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public class Category implements Serializable {
protected String messageRegex;
protected String traceRegex;
protected List<Status> matchedStatuses = new ArrayList<>();
protected boolean flaky;
protected Boolean flaky;

}
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,38 @@ meta, createTestResult("asd\n", Status.FAILED, true)
.containsKey("data/" + JSON_FILE_NAME);
}

@Test
void flakyTestsShouldBeMatchedByDefault() {
final Configuration configuration = ConfigurationBuilder.bundled().build();

final Category category = new Category()
.setName(CATEGORY_NAME)
.setMatchedStatuses(singletonList(Status.FAILED));

final Map<String, Object> meta = new HashMap<>();
meta.put("categories", singletonList(category));

final List<LaunchResults> launchResultsList = createSingleLaunchResults(
meta, createTestResult("asd\n", Status.FAILED, true)
);

final CategoriesPlugin plugin = new CategoriesPlugin();

final InMemoryReportStorage storage = new InMemoryReportStorage();
plugin.aggregate(configuration, launchResultsList, storage);

final Set<TestResult> results = launchResultsList.get(0).getAllResults();
List<Category> categories = results.toArray(new TestResult[]{})[0]
.getExtraBlock("categories");

assertThat(categories).as("test categories")
.extracting(Category::getName)
.containsExactly(category.getName());

assertThat(storage.getReportDataFiles())
.containsKey("data/" + JSON_FILE_NAME);
}

@Issue("587")
@Issue("572")
@Test
Expand Down

0 comments on commit 076f33d

Please sign in to comment.