public static List<HistoryTrendItem> randomHistoryTrendItems() { return Arrays.asList( randomHistoryTrendItem(), randomHistoryTrendItem(), randomHistoryTrendItem() ); }
public static List<LaunchResults> createSingleLaunchResults(TestResult... input) { return createSingleLaunchResults(new HashMap<>(), input); }
public static List<LaunchResults> createSingleLaunchResults(Map<String, Object> extra, TestResult... input) { List<LaunchResults> launchResultsList = new ArrayList<>(); launchResultsList.add(createLaunchResults(extra, input)); return launchResultsList; }
public static HistoryTrendItem randomHistoryTrendItem() { return new HistoryTrendItem() .setStatistic(randomStatistic()) .setBuildOrder(current().nextLong(100)) .setReportName(randomString()) .setReportUrl(randomString()); }
@Test public void shouldProcessNullBuildOrder() throws Exception { final Configuration configuration = mock(Configuration.class); final List<HistoryTrendItem> history = randomHistoryTrendItems(); final Map<String, Object> extra = new HashMap<>(); extra.put(HISTORY_TREND_BLOCK_NAME, history); extra.put(EXECUTORS_BLOCK_NAME, new ExecutorInfo().setBuildOrder(null)); final List<LaunchResults> launchResults = Arrays.asList( createLaunchResults(extra, randomTestResult().setStatus(Status.PASSED), randomTestResult().setStatus(Status.FAILED), randomTestResult().setStatus(Status.FAILED) ), createLaunchResults(extra, randomTestResult().setStatus(Status.PASSED), randomTestResult().setStatus(Status.FAILED), randomTestResult().setStatus(Status.FAILED) ) ); final List<HistoryTrendItem> data = new HistoryTrendPlugin().getData(launchResults); assertThat(data) .hasSize(1 + 2 * history.size()); } }
@Test public void shouldGetData() throws Exception { final Configuration configuration = mock(Configuration.class); final List<HistoryTrendItem> history = randomHistoryTrendItems(); final List<HistoryTrendItem> data = new HistoryTrendPlugin().getData(createSingleLaunchResults( singletonMap(HISTORY_TREND_BLOCK_NAME, history), randomTestResult().setStatus(Status.PASSED), randomTestResult().setStatus(Status.FAILED), randomTestResult().setStatus(Status.FAILED) )); assertThat(data) .hasSize(1 + history.size()) .extracting(HistoryTrendItem::getStatistic) .extracting(Statistic::getTotal, Statistic::getFailed, Statistic::getPassed) .first() .isEqualTo(Tuple.tuple(3L, 2L, 1L)); final List<HistoryTrendItem> next = data.subList(1, data.size()); assertThat(next) .containsExactlyElementsOf(history); }
public static TestResult randomTestResult() { return new TestResult().setName(randomString()); }
@BeforeClass public static void setUp() throws Exception { final Configuration configuration = new ConfigurationBuilder().useDefault().build(); final ReportGenerator generator = new ReportGenerator(configuration); output = folder.newFolder().toPath(); final Path resultsDirectory = folder.newFolder().toPath(); unpackDummyResources("allure1data/", resultsDirectory); generator.generate(output, resultsDirectory); }
@Test public void shouldRunOpen() throws Exception { final int port = randomPort(); final Path report = folder.newFolder().toPath(); when(commands.open(report, null, port)) .thenReturn(NO_ERROR); final Optional<ExitCode> exitCode = commandLine.parse( OPEN_COMMAND, "--port", String.valueOf(port), report.toString() ); assertThat(exitCode) .isEmpty(); final ExitCode code = commandLine.run(); verify(commands, times(1)).open(report, null, port); assertThat(code) .isEqualTo(NO_ERROR); }
private List<LaunchResults> getSimpleLaunchResults() { final TestResult first = new TestResult() .setName("first") .setLabels(singletonList(new Label().setName("suite").setValue("s1"))); final TestResult second = new TestResult() .setName("second") .setLabels(singletonList(new Label().setName("suite").setValue("s1"))); final TestResult third = new TestResult() .setName("third") .setLabels(singletonList(new Label().setName("suite").setValue("s2"))); return createSingleLaunchResults(second, first, third); } }
@Test public void shouldAllowResultsDirectoriesThatNotExists() throws Exception { final Optional<ExitCode> exitCode = commandLine.parse(GENERATE_COMMAND, randomString(), randomString()); assertThat(exitCode) .isEmpty(); }
@Test public void shouldNotMergeOtherTestResults() throws IOException { String firstHistoryId = UUID.randomUUID().toString(); String secondHistoryId = UUID.randomUUID().toString(); List<LaunchResults> launchResultsList = createSingleLaunchResults( createTestResult(FIRST_RESULT, firstHistoryId, 1L, 9L), createTestResult(SECOND_RESULT, secondHistoryId, 11L, 19L) ); retryPlugin.aggregate(null, launchResultsList, null); Set<TestResult> results = launchResultsList.get(0).getAllResults(); assertThat(results).as("test results") .filteredOn(TestResult::isHidden) .hasSize(0); assertThat(results).as("test results with retries block") .flatExtracting(result -> result.getExtraBlock(RETRY_BLOCK_NAME)) .hasSize(0); }
@Test public void shouldSkipHiddenResults() throws Exception { String historyId = UUID.randomUUID().toString(); List<LaunchResults> launchResultsList = createSingleLaunchResults( createTestResult(FIRST_RESULT, historyId, 1L, 9L), createTestResult(SECOND_RESULT, historyId, 11L, 19L), createTestResult(LAST_RESULT, historyId, 21L, 29L).setHidden(true) ); retryPlugin.aggregate(null, launchResultsList, null); Set<TestResult> results = launchResultsList.get(0).getAllResults(); assertThat(results) .filteredOn(TestResult::isHidden) .extracting(TestResult::getName) .containsExactlyInAnyOrder(FIRST_RESULT, LAST_RESULT); assertThat(results) .filteredOn(result -> !result.isHidden()) .extracting(TestResult::getName, TestResult::isFlaky) .containsExactlyInAnyOrder(tuple(SECOND_RESULT, true)); }
@Test public void shouldDefaultCategoriesToResults() throws Exception { final CategoriesPlugin categoriesPlugin = new CategoriesPlugin(); final TestResult first = new TestResult() .setName("first") .setStatus(Status.FAILED) .setStatusMessage("A"); final TestResult second = new TestResult() .setName("second") .setStatus(Status.BROKEN) .setStatusMessage("B"); categoriesPlugin.addCategoriesForResults(createSingleLaunchResults(first, second)); assertThat(first.getExtraBlock(CATEGORIES, new ArrayList<Category>())) .hasSize(1) .extracting(Category::getName) .containsExactlyInAnyOrder(FAILED_TESTS.getName()); assertThat(second.getExtraBlock(CATEGORIES, new ArrayList<Category>())) .hasSize(1) .extracting(Category::getName) .containsExactlyInAnyOrder(BROKEN_TESTS.getName()); }
@Test public void shouldNotMarkLatestAsFlakyIfRetriesArePassed() throws Exception { String historyId = UUID.randomUUID().toString(); List<LaunchResults> launchResultsList = createSingleLaunchResults( createTestResult(FIRST_RESULT, historyId, 1L, 9L).setStatus(Status.PASSED), createTestResult(SECOND_RESULT, historyId, 11L, 19L).setStatus(Status.PASSED) ); retryPlugin.aggregate(null, launchResultsList, null); Set<TestResult> results = launchResultsList.get(0).getAllResults(); assertThat(results) .filteredOn(TestResult::isHidden) .extracting(TestResult::getName) .containsExactlyInAnyOrder(FIRST_RESULT); assertThat(results) .filteredOn(result -> !result.isHidden()) .extracting(TestResult::getName, TestResult::isFlaky) .containsExactlyInAnyOrder(tuple(SECOND_RESULT, false)); }
@Test public void shouldSetCustomCategoriesToResults() throws Exception { final String categoryName = "Some category"; Category category = new Category() .setName(categoryName) .setMessageRegex(".*") .setMatchedStatuses(singletonList(Status.BROKEN)); Map<String, Object> meta = new HashMap<>(); meta.put("categories", singletonList(category)); final CategoriesPlugin categoriesPlugin = new CategoriesPlugin(); final TestResult first = new TestResult() .setName("first") .setStatus(Status.FAILED) .setStatusMessage("B"); final TestResult second = new TestResult() .setName("second") .setStatus(Status.BROKEN) .setStatusMessage("B"); categoriesPlugin.addCategoriesForResults(createSingleLaunchResults(meta, first, second)); assertThat(first.getExtraBlock(CATEGORIES, new ArrayList<Category>())) .hasSize(1) .extracting(Category::getName) .containsExactlyInAnyOrder(FAILED_TESTS.getName()); assertThat(second.getExtraBlock(CATEGORIES, new ArrayList<Category>())) .hasSize(1) .extracting(Category::getName) .containsExactlyInAnyOrder(categoryName); }
@Test public void shouldNotMarkLatestAsFlakyIfRetriesSkipped() throws Exception { String historyId = UUID.randomUUID().toString(); List<LaunchResults> launchResultsList = createSingleLaunchResults( createTestResult(FIRST_RESULT, historyId, 1L, 9L).setStatus(Status.SKIPPED), createTestResult(SECOND_RESULT, historyId, 11L, 19L).setStatus(Status.PASSED), createTestResult(LAST_RESULT, historyId, 12L, 20L).setHidden(true).setStatus(Status.PASSED) ); retryPlugin.aggregate(null, launchResultsList, null); Set<TestResult> results = launchResultsList.get(0).getAllResults(); assertThat(results) .filteredOn(TestResult::isHidden) .extracting(TestResult::getName) .containsExactlyInAnyOrder(FIRST_RESULT, LAST_RESULT); assertThat(results) .filteredOn(result -> !result.isHidden()) .extracting(TestResult::getName, TestResult::isFlaky) .containsExactlyInAnyOrder(tuple(SECOND_RESULT, false)); }
other.addExtraBlock(CATEGORIES, singletonList(new Category().setName("C3"))); final List<LaunchResults> launchResults = createSingleLaunchResults(first, second, third, other); final Tree<TestResult> tree = CategoriesPlugin.getData(launchResults);
@Issue("587") @Issue("572") @Test public void shouldSortByStartTimeAsc() throws Exception { final TestResult first = new TestResult() .setName("first") .setTime(new Time().setStart(10L)); final TestResult second = new TestResult() .setName("second") .setTime(new Time().setStart(12L)); final TestResult timeless = new TestResult() .setName("timeless"); final Tree<TestResult> tree = SuitesPlugin.getData( createSingleLaunchResults(second, first, timeless) ); assertThat(tree.getChildren()) .extracting(TreeNode::getName) .containsExactly("timeless", "first", "second"); }
@Issue("587") @Issue("572") @Test public void shouldSortByStartTimeAsc() throws Exception { final Category category = new Category().setName("some"); final TestResult first = new TestResult() .setName("first") .setStatus(Status.FAILED) .setTime(new Time().setStart(10L)); first.addExtraBlock(CATEGORIES, singletonList(category)); final TestResult second = new TestResult() .setName("second") .setStatus(Status.FAILED) .setTime(new Time().setStart(12L)); second.addExtraBlock(CATEGORIES, singletonList(category)); final TestResult timeless = new TestResult() .setName("timeless") .setStatus(Status.FAILED); timeless.addExtraBlock(CATEGORIES, singletonList(category)); final Tree<TestResult> tree = CategoriesPlugin.getData( createSingleLaunchResults(second, first, timeless) ); assertThat(tree.getChildren()) .flatExtracting("children") .flatExtracting("children") .extracting("name") .containsExactly("timeless", "first", "second"); }