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); }
public Optional<String> findOneLabel(final LabelName name) { return findOneLabel(name.value()); }
private SeverityData createData(final TestResult result) { return new SeverityData() .setUid(result.getUid()) .setName(result.getName()) .setStatus(result.getStatus()) .setTime(result.getTime()) .setSeverity(result.getExtraBlock(SEVERITY_BLOCK_NAME)); } }
private void setOwner(final TestResult result) { result.findOneLabel(LabelName.OWNER) .ifPresent(owner -> result.addExtraBlock(OWNER_BLOCK_NAME, owner)); } }
private Optional<TestResult> findLatest(final List<TestResult> results) { return results.stream() .filter(result -> !result.isHidden()) .min(comparingByTime()); }
final TestCaseResult source, final Properties properties) { final TestResult dest = new TestResult(); final String suiteName = firstNonNull(testSuite.getTitle(), testSuite.getName(), "unknown test suite"); final String testClass = firstNonNull( final Optional<ru.yandex.qatools.allure.model.Label> historyId = findLabel(source.getLabels(), "historyId"); if (historyId.isPresent()) { dest.setHistoryId(historyId.get().getValue()); } else { dest.setHistoryId(getHistoryId(String.format("%s#%s", testClass, name), parameters)); dest.setUid(randomUid.get()); dest.setName(name); dest.setFullName(String.format("%s.%s", testClass, testMethod)); dest.setStatus(status); dest.setTime(Time.create(source.getStart(), source.getStop())); dest.setParameters(parameters); dest.setDescription(getDescription(testSuite.getDescription(), source.getDescription())); dest.setDescriptionHtml(getDescriptionHtml(testSuite.getDescription(), source.getDescription())); Optional.ofNullable(source.getFailure()).ifPresent(failure -> { dest.setStatusMessage(failure.getMessage()); dest.setStatusTrace(failure.getStackTrace()); }); step -> convert(directory, visitor, step, status, dest.getStatusMessage(), dest.getStatusTrace())) );
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 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()); }
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)); } }
public static TestResult createTestResult(final Status status) { return new TestResult() .setUid(RandomStringUtils.random(10)) .setName(RandomStringUtils.random(10)) .setStatus(status); }
@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"); }
public CsvExportSuite(final TestResult result) { final Map<String, String> resultMap = result.toMap(); this.status = result.getStatus() != null ? result.getStatus().value() : null; this.duration = result.getTime().getDuration() != null ? result.getTime().getDuration().toString() : null; this.start = result.getTime().getStart() != null ? new Date(result.getTime().getStart()).toString() : null; this.stop = result.getTime().getStop() != null ? new Date(result.getTime().getStop()).toString() : null; this.parentSuite = resultMap.getOrDefault("parentSuite", null); this.suite = resultMap.getOrDefault("suite", null); this.subSuite = resultMap.getOrDefault("subSuite", null); this.testClass = resultMap.getOrDefault("testClass", null); this.testMethod = resultMap.getOrDefault("testMethod", null); this.name = result.getName(); this.description = result.getDescription(); }
private void updateHistory(final Map<String, HistoryData> history, final TestResult result, final ExecutorInfo info) { //@formatter:off final HistoryData data = history.computeIfAbsent( result.getHistoryId(), id -> new HistoryData().setStatistic(new Statistic()) ); //@formatter:on data.getStatistic().update(result); if (!data.getItems().isEmpty()) { result.addExtraBlock(HISTORY_BLOCK_NAME, copy(data)); } final HistoryItem newItem = new HistoryItem() .setUid(result.getUid()) .setStatus(result.getStatus()) .setStatusDetails(result.getStatusMessage()) .setTime(result.getTime()); if (Objects.nonNull(info.getReportUrl())) { newItem.setReportUrl(createReportUrl(info.getReportUrl(), result.getUid())); } final List<HistoryItem> newItems = Stream.concat(Stream.of(newItem), data.getItems().stream()) .limit(5) .collect(Collectors.toList()); data.setItems(newItems); }
@Test public void shouldCreateTree() throws Exception { 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"); first.addExtraBlock(CATEGORIES, singletonList(new Category().setName("C1"))); second.addExtraBlock(CATEGORIES, singletonList(new Category().setName("C2"))); third.addExtraBlock(CATEGORIES, singletonList(new Category().setName("C1"))); other.addExtraBlock(CATEGORIES, singletonList(new Category().setName("C3")));
@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"); }
private TestResult createTestResult(String message, Status status, boolean flaky) { return new TestResult() .setStatus(status) .setStatusMessage(message) .setFlaky(flaky); }
@Test public void shouldSkipResultsWithNonEmptyDescriptionHtml() throws Exception { final Path output = folder.newFolder().toPath(); final MarkdownDescriptionsPlugin aggregator = new MarkdownDescriptionsPlugin(); final TestResult result = new TestResult() .setName("some") .setDescription("desc") .setDescriptionHtml("descHtml"); final DefaultLaunchResults launchResults = new DefaultLaunchResults( Collections.singleton(result), Collections.emptyMap(), Collections.emptyMap() ); aggregator.aggregate(configuration, Collections.singletonList(launchResults), output); assertThat(result) .extracting(TestResult::getDescription, TestResult::getDescriptionHtml) .containsExactly("desc", "descHtml"); }
private RetryItem createRetryItem(final TestResult result) { return new RetryItem() .setStatus(result.getStatus()) .setStatusDetails(result.getStatusMessage()) .setTime(result.getTime()) .setUid(result.getUid()); }
.setLinks(links); verify(service).createTestResult(argThat(result -> testResult.getName().equals(result.getName()))); verify(service).createTestResult(argThat(result -> testResult.getStatus().toString().equals(result.getStatus()))); verify(service).createTestResult(argThat(result -> result.getUrl().contains(testResult.getUid()))); verify(service).createTestResult(argThat(result -> Objects.nonNull(result.getLaunchId())));