diff --git a/allure-generator/src/main/java/io/qameta/allure/category/CategoriesPlugin.java b/allure-generator/src/main/java/io/qameta/allure/category/CategoriesPlugin.java index 4ce842037..d57a24227 100644 --- a/allure-generator/src/main/java/io/qameta/allure/category/CategoriesPlugin.java +++ b/allure-generator/src/main/java/io/qameta/allure/category/CategoriesPlugin.java @@ -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; @@ -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; } diff --git a/allure-generator/src/main/java/io/qameta/allure/category/Category.java b/allure-generator/src/main/java/io/qameta/allure/category/Category.java index 6e6ab3888..5f8c488dd 100644 --- a/allure-generator/src/main/java/io/qameta/allure/category/Category.java +++ b/allure-generator/src/main/java/io/qameta/allure/category/Category.java @@ -38,6 +38,6 @@ public class Category implements Serializable { protected String messageRegex; protected String traceRegex; protected List matchedStatuses = new ArrayList<>(); - protected boolean flaky; + protected Boolean flaky; } diff --git a/allure-generator/src/test/java/io/qameta/allure/category/CategoriesPluginTest.java b/allure-generator/src/test/java/io/qameta/allure/category/CategoriesPluginTest.java index 792de5611..3a9c29ce9 100644 --- a/allure-generator/src/test/java/io/qameta/allure/category/CategoriesPluginTest.java +++ b/allure-generator/src/test/java/io/qameta/allure/category/CategoriesPluginTest.java @@ -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 meta = new HashMap<>(); + meta.put("categories", singletonList(category)); + + final List 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 results = launchResultsList.get(0).getAllResults(); + List 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