diff --git a/allure-testng/src/main/java/io/qameta/allure/testng/AllureTestNg.java b/allure-testng/src/main/java/io/qameta/allure/testng/AllureTestNg.java index 41b7c362..ea6148a3 100644 --- a/allure-testng/src/main/java/io/qameta/allure/testng/AllureTestNg.java +++ b/allure-testng/src/main/java/io/qameta/allure/testng/AllureTestNg.java @@ -51,6 +51,7 @@ import org.testng.ITestNGMethod; import org.testng.ITestResult; import org.testng.annotations.Parameters; +import org.testng.annotations.Test; import org.testng.internal.ConstructorOrMethod; import org.testng.xml.XmlSuite; import org.testng.xml.XmlTest; @@ -807,6 +808,7 @@ private List getParameters(final ITestContext context, private String getMethodName(final ITestNGMethod method) { return firstNonEmpty( + getTestNameFromAnnotation(method), method.getDescription(), method.getMethodName(), getQualifiedName(method)).orElse("Unknown"); @@ -877,6 +879,25 @@ private static boolean isClassAvailableOnClasspath(final String clazz) { } } + private String getTestNameFromAnnotation(final ITestNGMethod iTestNGMethod) { + final ConstructorOrMethod constructorOrMethod = iTestNGMethod.getConstructorOrMethod(); + if (Objects.isNull(constructorOrMethod)) { + return null; + } + + final Method method = constructorOrMethod.getMethod(); + if (Objects.isNull(method)) { + return null; + } + + final Test annotation = method.getAnnotation(Test.class); + if (Objects.isNull(annotation)) { + return null; + } + + return annotation.testName(); + } + /** * The stage of current result context. */ diff --git a/allure-testng/src/test/java/io/qameta/allure/testng/AllureTestNgTest.java b/allure-testng/src/test/java/io/qameta/allure/testng/AllureTestNgTest.java index 7af9c530..f7d4c87b 100644 --- a/allure-testng/src/test/java/io/qameta/allure/testng/AllureTestNgTest.java +++ b/allure-testng/src/test/java/io/qameta/allure/testng/AllureTestNgTest.java @@ -997,7 +997,11 @@ public void shouldProcessCyrillicDescriptions() { assertThat(results.getTestResults()) .extracting(TestResult::getName) - .containsExactlyInAnyOrder("Тест с описанием на русском языке"); + .contains( + "Тест с описанием на русском языке только в testName", + "Тест с описанием на русском языке только в description", + "Тест с описанием на русском языке и в testName" + ); } @AllureFeatures.Fixtures diff --git a/allure-testng/src/test/java/io/qameta/allure/testng/samples/CyrillicDescriptions.java b/allure-testng/src/test/java/io/qameta/allure/testng/samples/CyrillicDescriptions.java index 475ffb5b..8418a3fd 100644 --- a/allure-testng/src/test/java/io/qameta/allure/testng/samples/CyrillicDescriptions.java +++ b/allure-testng/src/test/java/io/qameta/allure/testng/samples/CyrillicDescriptions.java @@ -22,7 +22,16 @@ */ public class CyrillicDescriptions { - @Test(description = "Тест с описанием на русском языке") + @Test(testName = "Тест с описанием на русском языке только в testName") + public void testWithCyrillicTestName() throws Exception { + } + + @Test(description = "Тест с описанием на русском языке только в description") public void testWithCyrillicDescription() throws Exception { } + + @Test(testName = "Тест с описанием на русском языке и в testName", + description = "Тест с описанием на русском языке и в description") + public void testWithCyrillicTestNameAndDescription() throws Exception { + } }