@Test public void shouldFindLabelsInEmptyArray() throws Exception { final Optional<String> found = new TestResult().findOneLabel("hey"); assertThat(found) .isEmpty(); }
public static TestResult randomTestResult() { return new TestResult().setName(randomString()); }
private TestResult createTestResult(String message, Status status, boolean flaky) { return new TestResult() .setStatus(status) .setStatusMessage(message) .setFlaky(flaky); }
@Test public void shouldExportTestResultToJira() { final LaunchResults launchResults = mock(LaunchResults.class); final TestResult testResult = new TestResult() .setLabels(Collections.singletonList(new Label().setName("testClass").setValue(TEST_CLASS))); final Set<TestResult> results = new HashSet<>(Collections.singletonList(testResult)); when(launchResults.getAllResults()).thenReturn(results); final IdeaLinksPlugin jiraTestResultExportPlugin = new IdeaLinksPlugin(); jiraTestResultExportPlugin.aggregate( mock(Configuration.class), Collections.singletonList(launchResults), Paths.get("/") ); assertThat(testResult.getLinks()).hasSize(1); final Link link = testResult.getLinks().get(0); assertThat(link.getName()).isEqualTo("Open in Idea"); assertThat(link.getType()).isEqualTo("idea"); assertThat(link.getUrl()).contains(TEST_CLASS.replace(".", "/")); }
@Test public void shouldSkipResultsWithEmptyDescription() throws Exception { final Path output = folder.newFolder().toPath(); final MarkdownDescriptionsPlugin aggregator = new MarkdownDescriptionsPlugin(); final TestResult result = new TestResult().setName("some"); 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(null, null); }
@Test public void shouldProcessDescription() throws Exception { final Path output = folder.newFolder().toPath(); final MarkdownDescriptionsPlugin aggregator = new MarkdownDescriptionsPlugin(); final TestResult result = new TestResult() .setName("some") .setDescription("desc"); 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", "<p>desc</p>\n"); } }
@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"); }
@Test public void shouldFindOneWithNullValue() throws Exception { final TestResult result = new TestResult(); result.getLabels().add(new Label().setName("hey").setValue(null)); final Optional<String> found = result.findOneLabel("hey"); assertThat(found) .isEmpty(); }
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); } }
public static TestResult createTestResult(final Status status) { return new TestResult() .setUid(RandomStringUtils.random(10)) .setName(RandomStringUtils.random(10)) .setStatus(status); }
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 TestResult first = new TestResult() .setName("first") .setTime(new Time().setStart(10L)); final TestResult second = new TestResult() .setName("second") .setTime(new Time().setStart(100L)); final TestResult third = new TestResult() .setName("third") .setTime(new Time().setStart(50L)); final TestResult timeless = new TestResult() .setName("timeless"); final LaunchResults results = new DefaultLaunchResults( new HashSet<>(Arrays.asList(first, second, third, timeless)), Collections.emptyMap(), Collections.emptyMap() ); final PackagesPlugin packagesPlugin = new PackagesPlugin(); final Tree<TestResult> tree = packagesPlugin.getData(singletonList(results)); assertThat(tree.getChildren()) .extracting("name") .containsExactly("timeless", "first", "third", "second"); } }
final Set<TestResult> testResults = new HashSet<>(); final TestResult first = new TestResult() .setName("first") .setLabels(asList(PACKAGE.label("a.b"), TEST_METHOD.label("firstMethod"))); final TestResult second = new TestResult() .setName("second") .setLabels(singletonList(PACKAGE.label("a.c")));
@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 shouldFindAllWithNullValue() throws Exception { final TestResult result = new TestResult(); result.getLabels().add(new Label().setName("hey").setValue(null)); result.getLabels().add(new Label().setName("hey").setValue("a")); result.getLabels().add(new Label().setName("hey").setValue("b")); final List<String> found = result.findAllLabels("hey"); assertThat(found) .containsExactlyInAnyOrder(null, "a", "b"); } }
@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); }
@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 name, String historyId, long start, long stop) { return new TestResult() .setName(name) .setHistoryId(historyId) .setStatus(Status.BROKEN) .setTime(new Time().setStart(start).setStop(stop)); } }
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); }
@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"); }