CategoriesPlugin extends CompositeAggregator implements Reader { @Override public void aggregate(final Configuration configuration, final List<LaunchResults> launchesResults, final Path outputDirectory) throws IOException { addCategoriesForResults(launchesResults); super.aggregate(configuration, launchesResults, outputDirectory); } CategoriesPlugin(); @Override void readResults(final Configuration configuration,
                            final ResultsVisitor visitor,
                            final Path directory); static boolean matches(final TestResult result, final Category category); @Override void aggregate(final Configuration configuration,
                          final List<LaunchResults> launchesResults,
                          final Path outputDirectory); static final String CATEGORIES; static final Category FAILED_TESTS; static final Category BROKEN_TESTS; static final String JSON_FILE_NAME; static final String CSV_FILE_NAME; }
@Test void shouldWork() throws IOException { Category category = new Category() .setName(CATEGORY_NAME) .setMessageRegex(".*") .setMatchedStatuses(singletonList(Status.BROKEN)); Map<String, Object> meta = new HashMap<>(); meta.put("categories", singletonList(category)); List<LaunchResults> launchResultsList = createSingleLaunchResults( meta, createTestResult("asd\n", Status.BROKEN) ); CategoriesPlugin plugin = new CategoriesPlugin(); plugin.aggregate(configuration, launchResultsList, reportPath); 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(reportPath.resolve("data").resolve(JSON_FILE_NAME)) .exists(); assertThat(reportPath.resolve("data").resolve(CSV_FILE_NAME)) .exists(); }
@Test void flakyTestsCanBeAddedToCategory() throws IOException { Category category = new Category() .setName(CATEGORY_NAME) .setMatchedStatuses(singletonList(Status.FAILED)) .setFlaky(true); Map<String, Object> meta = new HashMap<>(); meta.put("categories", singletonList(category)); List<LaunchResults> launchResultsList = createSingleLaunchResults( meta, createTestResult("asd\n", Status.FAILED, true) ); CategoriesPlugin plugin = new CategoriesPlugin(); plugin.aggregate(configuration, launchResultsList, reportPath); 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(reportPath.resolve("data").resolve(JSON_FILE_NAME)) .exists(); }