private TestResult createTestResult(String message, Status status, boolean flaky) { return new TestResult() .setStatus(status) .setStatusMessage(message) .setFlaky(flaky); }
@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()); } }
private void convert(final Supplier<String> uidGenerator, final Path resultsDirectory, final ResultsVisitor visitor, final List<TestResultContainer> groups, final TestResult result) { final io.qameta.allure.entity.TestResult dest = new io.qameta.allure.entity.TestResult(); dest.setUid(uidGenerator.get()); dest.setHistoryId(result.getHistoryId()); dest.setFullName(result.getFullName()); dest.setName(firstNonNull(result.getName(), result.getFullName(), "Unknown test")); dest.setTime(Time.create(result.getStart(), result.getStop())); dest.setDescription(result.getDescription()); dest.setDescriptionHtml(result.getDescriptionHtml()); dest.setStatus(convert(result.getStatus())); Optional.ofNullable(result.getStatusDetails()).ifPresent(details -> { dest.setStatusMessage(details.getMessage()); dest.setStatusTrace(details.getTrace()); }); dest.setLinks(convert(result.getLinks(), this::convert)); dest.setLabels(convert(result.getLabels(), this::convert)); dest.setParameters(getParameters(result)); dest.addLabelIfNotExists(RESULT_FORMAT, ALLURE2_RESULTS_FORMAT); if (hasTestStage(result)) { dest.setTestStage(getTestStage(resultsDirectory, visitor, result)); } final List<TestResultContainer> parents = findAllParents(groups, result.getUuid(), new HashSet<>()); dest.getBeforeStages().addAll(getStages(parents, fixture -> getBefore(resultsDirectory, visitor, fixture))); dest.getAfterStages().addAll(getStages(parents, fixture -> getAfter(resultsDirectory, visitor, fixture))); visitor.visitTestResult(dest); }
dest.setStatus(status); dest.setTime(Time.create(source.getStart(), source.getStop())); dest.setParameters(parameters);
@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 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); }
private void convert(final Supplier<String> uidGenerator, final Path resultsDirectory, final ResultsVisitor visitor, final List<TestResultContainer> groups, final TestResult result) { final io.qameta.allure.entity.TestResult dest = new io.qameta.allure.entity.TestResult(); dest.setUid(uidGenerator.get()); dest.setHistoryId(result.getHistoryId()); dest.setFullName(result.getFullName()); dest.setName(firstNonNull(result.getName(), result.getFullName(), "Unknown test")); dest.setTime(Time.create(result.getStart(), result.getStop())); dest.setDescription(result.getDescription()); dest.setDescriptionHtml(result.getDescriptionHtml()); dest.setStatus(convert(result.getStatus())); Optional.ofNullable(result.getStatusDetails()).ifPresent(details -> { dest.setStatusMessage(details.getMessage()); dest.setStatusTrace(details.getTrace()); }); dest.setLinks(convert(result.getLinks(), this::convert)); dest.setLabels(convert(result.getLabels(), this::convert)); dest.setParameters(getParameters(result)); dest.addLabelIfNotExists(RESULT_FORMAT, ALLURE2_RESULTS_FORMAT); if (hasTestStage(result)) { dest.setTestStage(getTestStage(resultsDirectory, visitor, result)); } final List<TestResultContainer> parents = findAllParents(groups, result.getUuid(), new HashSet<>()); dest.getBeforeStages().addAll(getStages(parents, fixture -> getBefore(resultsDirectory, visitor, fixture))); dest.getAfterStages().addAll(getStages(parents, fixture -> getAfter(resultsDirectory, visitor, fixture))); visitor.visitTestResult(dest); }
@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 shouldFindLatestExecutor() throws Exception { final Configuration configuration = mock(Configuration.class); final Map<String, Object> extra1 = new HashMap<>(); final List<HistoryTrendItem> history1 = randomHistoryTrendItems(); extra1.put(HISTORY_TREND_BLOCK_NAME, history1); extra1.put(EXECUTORS_BLOCK_NAME, new ExecutorInfo().setBuildOrder(1L)); final Map<String, Object> extra2 = new HashMap<>(); final List<HistoryTrendItem> history2 = randomHistoryTrendItems(); extra2.put(HISTORY_TREND_BLOCK_NAME, history2); extra2.put(EXECUTORS_BLOCK_NAME, new ExecutorInfo().setBuildOrder(7L)); final List<LaunchResults> launchResults = Arrays.asList( createLaunchResults(extra1, randomTestResult().setStatus(Status.PASSED), randomTestResult().setStatus(Status.FAILED), randomTestResult().setStatus(Status.FAILED) ), createLaunchResults(extra2, randomTestResult().setStatus(Status.PASSED), randomTestResult().setStatus(Status.FAILED), randomTestResult().setStatus(Status.FAILED) ) ); final List<HistoryTrendItem> data = new HistoryTrendPlugin().getData(launchResults); assertThat(data) .hasSize(1 + history1.size() + history2.size()); final HistoryTrendItem historyTrendItem = data.get(0); assertThat(historyTrendItem) .hasFieldOrPropertyWithValue("buildOrder", 7L); }
dest.setStatus(status); dest.setTime(Time.create(source.getStart(), source.getStop())); dest.setParameters(parameters);
final TestResult first = new TestResult() .setName("first") .setStatus(Status.BROKEN) .setStatusMessage("M1"); final TestResult second = new TestResult() .setName("second") .setStatus(Status.FAILED) .setStatusMessage("M2"); final TestResult third = new TestResult() .setName("third") .setStatus(Status.BROKEN) .setStatusMessage("M3"); final TestResult other = new TestResult() .setName("other") .setStatus(Status.PASSED) .setStatusMessage("M4");
@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)); }
public static TestResult createTestResult(final Status status) { return new TestResult() .setUid(RandomStringUtils.random(10)) .setName(RandomStringUtils.random(10)) .setStatus(status); }
@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)); }
public static TestResult createTestResult(final Status status) { return new TestResult() .setUid(RandomStringUtils.random(10)) .setName(RandomStringUtils.random(10)) .setStatus(status); }
private TestResult createTestResult(String name, String historyId, long start, long stop) { return new TestResult() .setName(name) .setHistoryId(historyId) .setStatus(Status.BROKEN) .setTime(new Time().setStart(start).setStop(stop)); } }
@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"); }