Skip to content

Commit 87e5e9d

Browse files
authored
add junit platform test unique id to result metadata (fixes ##593, via#594)
1 parent 5cb5922 commit 87e5e9d

3 files changed

Lines changed: 53 additions & 0 deletions

File tree

allure-junit-platform/src/main/java/io/qameta/allure/junitplatform/AllureJunitPlatform.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ public class AllureJunitPlatform implements TestExecutionListener {
100100
public static final String EVENT_STOP = "stop";
101101
public static final String EVENT_FAILURE = "failure";
102102

103+
public static final String JUNIT_PLATFORM_UNIQUE_ID = "junit.platform.uniqueid";
104+
103105
private static final String STDOUT = "stdout";
104106
private static final String STDERR = "stderr";
105107
private static final String TEXT_PLAIN = "text/plain";
@@ -373,6 +375,8 @@ private void startTestCase(final TestIdentifier testIdentifier) {
373375

374376
result.getLabels().addAll(getProvidedLabels());
375377

378+
result.getLabels().add(getJUnitPlatformUniqueId(testIdentifier));
379+
376380
testClass.map(AnnotationUtils::getLabels).ifPresent(result.getLabels()::addAll);
377381
testMethod.map(AnnotationUtils::getLabels).ifPresent(result.getLabels()::addAll);
378382

@@ -510,6 +514,13 @@ private List<Label> getSourceLabels(final TestSource source) {
510514
return Collections.emptyList();
511515
}
512516

517+
private Label getJUnitPlatformUniqueId(final TestIdentifier testIdentifier) {
518+
final Label label = new Label();
519+
label.setName(JUNIT_PLATFORM_UNIQUE_ID);
520+
label.setValue(testIdentifier.getUniqueId());
521+
return label;
522+
}
523+
513524
private static class Uuids {
514525

515526
private final Map<TestIdentifier, String> storage = new ConcurrentHashMap<>();

allure-junit-platform/src/test/java/io/qameta/allure/junitplatform/AllureJunitPlatformTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import io.qameta.allure.junitplatform.features.DisabledTests;
2727
import io.qameta.allure.junitplatform.features.DynamicTests;
2828
import io.qameta.allure.junitplatform.features.FailedTests;
29+
import io.qameta.allure.junitplatform.features.JupiterUniqueIdTest;
2930
import io.qameta.allure.junitplatform.features.MarkerAnnotationSupport;
3031
import io.qameta.allure.junitplatform.features.OneTest;
3132
import io.qameta.allure.junitplatform.features.OwnerTest;
@@ -70,6 +71,7 @@
7071
import java.util.Optional;
7172
import java.util.stream.Collectors;
7273

74+
import static io.qameta.allure.junitplatform.AllureJunitPlatform.JUNIT_PLATFORM_UNIQUE_ID;
7375
import static io.qameta.allure.junitplatform.AllureJunitPlatformTestUtils.runClasses;
7476
import static io.qameta.allure.junitplatform.features.TaggedTests.CLASS_TAG;
7577
import static io.qameta.allure.junitplatform.features.TaggedTests.METHOD_TAG;
@@ -759,4 +761,16 @@ void shouldSupportAllureIdAnnotations() {
759761

760762
}
761763

764+
@AllureFeatures.Base
765+
@Test
766+
void shouldPopulateTestCaseId() {
767+
final AllureResults results = runClasses(JupiterUniqueIdTest.class);
768+
final List<TestResult> testResults = results.getTestResults();
769+
assertThat(testResults)
770+
.flatExtracting(TestResult::getLabels)
771+
.filteredOn("name", JUNIT_PLATFORM_UNIQUE_ID)
772+
.extracting(Label::getValue)
773+
.first()
774+
.isEqualTo("[engine:junit-jupiter]/[class:io.qameta.allure.junitplatform.features.JupiterUniqueIdTest]/[method:jupiterTest()]");
775+
}
762776
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2019 Qameta Software OÜ
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.qameta.allure.junitplatform.features;
17+
18+
import org.junit.jupiter.api.Test;
19+
20+
/**
21+
* @author naresha (Naresha K)
22+
*/
23+
public class JupiterUniqueIdTest {
24+
25+
@Test
26+
void jupiterTest() {
27+
}
28+
}

0 commit comments

Comments
 (0)