Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,16 @@ private void startTestCase(final TestIdentifier testIdentifier) {

result.getLabels().add(getJUnitPlatformUniqueId(testIdentifier));

testClass.map(AnnotationUtils::getLabels).ifPresent(result.getLabels()::addAll);
// add annotations from outer classes (support for @Nested tests in JUnit 5)
testClass.ifPresent(clazz -> {
Class<?> clazz1 = clazz;
do {
final Set<Label> labels = AnnotationUtils.getLabels(clazz1);
result.getLabels().addAll(labels);
clazz1 = clazz1.getDeclaringClass();
} while (Objects.nonNull(clazz1));
});

testMethod.map(AnnotationUtils::getLabels).ifPresent(result.getLabels()::addAll);

testClass.map(AnnotationUtils::getLinks).ifPresent(result.getLinks()::addAll);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.qameta.allure.junitplatform.features.FailedTests;
import io.qameta.allure.junitplatform.features.JupiterUniqueIdTest;
import io.qameta.allure.junitplatform.features.MarkerAnnotationSupport;
import io.qameta.allure.junitplatform.features.NestedTests;
import io.qameta.allure.junitplatform.features.OneTest;
import io.qameta.allure.junitplatform.features.OwnerTest;
import io.qameta.allure.junitplatform.features.ParallelTests;
Expand Down Expand Up @@ -873,4 +874,54 @@ void shouldSetDifferentUuidsInDifferentRuns() {

}

@Test
void shouldSupportNestedClasses() {
final AllureResults allureResults = runClasses(NestedTests.class);

assertThat(allureResults.getTestResults())
.extracting(TestResult::getName)
.containsExactlyInAnyOrder(
"parentTest()",
"feature1Test()",
"feature2Test()",
"story1Test()"
);

assertThat(allureResults.getTestResults())
.filteredOn("name", "parentTest()")
.flatExtracting(TestResult::getLabels)
.extracting(Label::getName, Label::getValue)
.contains(
tuple("epic", "Parent epic"),
tuple("feature", "Parent feature")
);

assertThat(allureResults.getTestResults())
.filteredOn("name", "feature1Test()")
.flatExtracting(TestResult::getLabels)
.extracting(Label::getName, Label::getValue)
.contains(
tuple("epic", "Parent epic"),
tuple("feature", "Feature 1")
);

assertThat(allureResults.getTestResults())
.filteredOn("name", "feature2Test()")
.flatExtracting(TestResult::getLabels)
.extracting(Label::getName, Label::getValue)
.contains(
tuple("epic", "Parent epic"),
tuple("feature", "Feature 2")
);

assertThat(allureResults.getTestResults())
.filteredOn("name", "story1Test()")
.flatExtracting(TestResult::getLabels)
.extracting(Label::getName, Label::getValue)
.contains(
tuple("epic", "Parent epic"),
tuple("feature", "Feature 2"),
tuple("story", "Story 1")
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2016-2024 Qameta Software Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.qameta.allure.junitplatform.features;

import io.qameta.allure.Epic;
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

/**
* @author charlie (Dmitry Baev).
*/
@Epic("Parent epic")
public class NestedTests {

@Feature("Parent feature")
@Test
void parentTest() {
}

@Feature("Feature 1")
@Nested
class Feature1 {

@Test
void feature1Test() {
}
}

@Feature("Feature 2")
@Nested
class Feature2 {

@Test
void feature2Test() {
}

@Story("Story 1")
@Nested
class Story1 {

@Test
void story1Test() {
}

}
}
}