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 @@ -15,6 +15,7 @@
*/
package io.qameta.allure.junitplatform;

import org.junit.platform.commons.JUnitException;
import org.junit.platform.engine.TestSource;
import org.junit.platform.engine.support.descriptor.ClassSource;
import org.junit.platform.engine.support.descriptor.ClasspathResourceSource;
Expand All @@ -24,7 +25,6 @@

import java.lang.reflect.Method;
import java.util.Optional;
import java.util.stream.Stream;
/* package-private */ final class AllureJunitPlatformUtils {

private static final Logger LOGGER = LoggerFactory.getLogger(AllureJunitPlatformUtils.class);
Expand Down Expand Up @@ -81,11 +81,10 @@ static Optional<Method> getTestMethod(final TestSource source) {

static Optional<Method> getTestMethod(final MethodSource source) {
try {
final Class<?> aClass = Class.forName(source.getClassName());
return Stream.of(aClass.getDeclaredMethods())
.filter(method -> MethodSource.from(method).equals(source))
.findAny();
} catch (ClassNotFoundException e) {
// resolves the method in the whole class hierarchy, including
// test methods inherited from super classes
return Optional.ofNullable(source.getJavaMethod());
} catch (JUnitException e) {
LOGGER.trace("Could not get test method from method source {}", source, e);
}
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@
import io.qameta.allure.junitplatform.features.TestWithClassLinks;
import io.qameta.allure.junitplatform.features.TestWithDescription;
import io.qameta.allure.junitplatform.features.TestWithDisplayName;
import io.qameta.allure.junitplatform.features.TestWithInheritedMetadata;
import io.qameta.allure.junitplatform.features.TestWithInterfaceDefaultMetadata;
import io.qameta.allure.junitplatform.features.TestWithMethodLabels;
import io.qameta.allure.junitplatform.features.TestWithMethodLinks;
import io.qameta.allure.junitplatform.features.TestWithOverriddenMetadata;
import io.qameta.allure.junitplatform.features.TestWithPublishedFile;
import io.qameta.allure.junitplatform.features.TestWithSteps;
import io.qameta.allure.junitplatform.features.TestWithSystemErr;
Expand Down Expand Up @@ -94,6 +97,7 @@
import static io.qameta.allure.test.AllurePredicates.hasLabel;
import static io.qameta.allure.test.AllurePredicates.hasStatus;
import static io.qameta.allure.util.ResultsUtils.ALLURE_ID_LABEL_NAME;
import static io.qameta.allure.util.ResultsUtils.EPIC_LABEL_NAME;
import static io.qameta.allure.util.ResultsUtils.FEATURE_LABEL_NAME;
import static io.qameta.allure.util.ResultsUtils.HOST_LABEL_NAME;
import static io.qameta.allure.util.ResultsUtils.OWNER_LABEL_NAME;
Expand Down Expand Up @@ -448,6 +452,89 @@ void shouldProcessMethodLabels() {
);
}

@Test
@AllureFeatures.MarkerAnnotations
@Issue("1032")
void shouldProcessAnnotationsOnInheritedTestMethods() {
final AllureResults results = runClasses(TestWithInheritedMetadata.class);
final List<TestResult> testResults = results.getTestResults();
assertThat(testResults)
.hasSize(1);

final TestResult testResult = testResults.get(0);
assertThat(testResult.getDescription())
.isEqualTo("Inherited test description");

assertThat(testResult.getLabels())
.extracting(Label::getName, Label::getValue)
.contains(
tuple(EPIC_LABEL_NAME, "inherited-epic"),
tuple(FEATURE_LABEL_NAME, "inherited-feature"),
tuple(STORY_LABEL_NAME, "inherited-story"),
tuple(OWNER_LABEL_NAME, "inherited-owner"),
tuple(SEVERITY_LABEL_NAME, "critical")
);

assertThat(testResult.getLinks())
.extracting(Link::getName, Link::getUrl)
.contains(tuple("INHERITED-LINK", "https://example.org/inherited"));
}

@Test
@AllureFeatures.MarkerAnnotations
@Issue("1032")
void shouldProcessAnnotationsOnInterfaceDefaultTestMethods() {
final AllureResults results = runClasses(TestWithInterfaceDefaultMetadata.class);
final List<TestResult> testResults = results.getTestResults();
assertThat(testResults)
.hasSize(1);

final TestResult testResult = testResults.get(0);
assertThat(testResult.getDescription())
.isEqualTo("Interface default test description");

assertThat(testResult.getLabels())
.extracting(Label::getName, Label::getValue)
.contains(
tuple(STORY_LABEL_NAME, "interface-story"),
tuple(OWNER_LABEL_NAME, "interface-owner"),
tuple(SEVERITY_LABEL_NAME, "minor")
);

assertThat(testResult.getLinks())
.extracting(Link::getName, Link::getUrl)
.contains(tuple("INTERFACE-LINK", "https://example.org/interface"));
}

@Test
@AllureFeatures.MarkerAnnotations
@Issue("1032")
void shouldUseOverriddenTestMethodAnnotations() {
final AllureResults results = runClasses(TestWithOverriddenMetadata.class);
final List<TestResult> testResults = results.getTestResults();
assertThat(testResults)
.hasSize(1);

// the overriding method fully replaces the inherited one, so only
// the annotations declared on the override are reported
final TestResult testResult = testResults.get(0);
assertThat(testResult.getDescription())
.isEqualTo("Overridden test description");

assertThat(testResult.getLabels())
.extracting(Label::getName, Label::getValue)
.contains(tuple(STORY_LABEL_NAME, "overridden-story"))
.doesNotContain(
tuple(STORY_LABEL_NAME, "interface-story"),
tuple(OWNER_LABEL_NAME, "interface-owner"),
tuple(SEVERITY_LABEL_NAME, "minor")
);

assertThat(testResult.getLinks())
.extracting(Link::getName)
.doesNotContain("INTERFACE-LINK");
}

@Test
@AllureFeatures.MarkerAnnotations
void shouldProcessClassLabels() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2016-2026 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.Description;
import io.qameta.allure.Epic;
import io.qameta.allure.Feature;
import io.qameta.allure.Link;
import io.qameta.allure.Owner;
import io.qameta.allure.Severity;
import io.qameta.allure.SeverityLevel;
import io.qameta.allure.Story;
import org.junit.jupiter.api.Test;

public abstract class AbstractTestWithMetadata {

@Test
@Description("Inherited test description")
@Epic("inherited-epic")
@Feature("inherited-feature")
@Story("inherited-story")
@Owner("inherited-owner")
@Severity(SeverityLevel.CRITICAL)
@Link(
name = "INHERITED-LINK",
url = "https://example.org/inherited"
)
void inheritedTest() {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2016-2026 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.Description;
import io.qameta.allure.Link;
import io.qameta.allure.Owner;
import io.qameta.allure.Severity;
import io.qameta.allure.SeverityLevel;
import io.qameta.allure.Story;
import org.junit.jupiter.api.Test;

public interface InterfaceWithMetadata {

@Test
@Description("Interface default test description")
@Story("interface-story")
@Owner("interface-owner")
@Severity(SeverityLevel.MINOR)
@Link(
name = "INTERFACE-LINK",
url = "https://example.org/interface"
)
default void interfaceDefaultTest() {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright 2016-2026 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;
public class TestWithInheritedMetadata extends AbstractTestWithMetadata {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright 2016-2026 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;
public class TestWithInterfaceDefaultMetadata implements InterfaceWithMetadata {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2016-2026 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.Description;
import io.qameta.allure.Story;
import org.junit.jupiter.api.Test;

public class TestWithOverriddenMetadata implements InterfaceWithMetadata {

@Test
@Override
@Description("Overridden test description")
@Story("overridden-story")
public void interfaceDefaultTest() {
}

}
Loading