Skip to content

Commit 90adc1e

Browse files
committed
[TestNG] Lookup test name for report first in 'testName' field inside 'Test' annotation
1 parent 5dc185e commit 90adc1e

3 files changed

Lines changed: 36 additions & 2 deletions

File tree

allure-testng/src/main/java/io/qameta/allure/testng/AllureTestNg.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.testng.ITestNGMethod;
5252
import org.testng.ITestResult;
5353
import org.testng.annotations.Parameters;
54+
import org.testng.annotations.Test;
5455
import org.testng.internal.ConstructorOrMethod;
5556
import org.testng.xml.XmlSuite;
5657
import org.testng.xml.XmlTest;
@@ -811,6 +812,7 @@ private List<Parameter> getParameters(final ITestContext context,
811812

812813
private String getMethodName(final ITestNGMethod method) {
813814
return firstNonEmpty(
815+
getTestNameFromAnnotation(method),
814816
method.getDescription(),
815817
method.getMethodName(),
816818
getQualifiedName(method)).orElse("Unknown");
@@ -881,6 +883,25 @@ private static boolean isClassAvailableOnClasspath(final String clazz) {
881883
}
882884
}
883885

886+
private String getTestNameFromAnnotation(final ITestNGMethod iTestNGMethod) {
887+
final ConstructorOrMethod constructorOrMethod = iTestNGMethod.getConstructorOrMethod();
888+
if (Objects.isNull(constructorOrMethod)) {
889+
return null;
890+
}
891+
892+
final Method method = constructorOrMethod.getMethod();
893+
if (Objects.isNull(method)) {
894+
return null;
895+
}
896+
897+
final Test annotation = method.getAnnotation(Test.class);
898+
if (Objects.isNull(annotation)) {
899+
return null;
900+
}
901+
902+
return annotation.testName();
903+
}
904+
884905
/**
885906
* The stage of current result context.
886907
*/

allure-testng/src/test/java/io/qameta/allure/testng/AllureTestNgTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,11 @@ public void shouldProcessCyrillicDescriptions() {
997997

998998
assertThat(results.getTestResults())
999999
.extracting(TestResult::getName)
1000-
.containsExactlyInAnyOrder("Тест с описанием на русском языке");
1000+
.contains(
1001+
"Тест с описанием на русском языке только в testName",
1002+
"Тест с описанием на русском языке только в description",
1003+
"Тест с описанием на русском языке и в testName"
1004+
);
10011005
}
10021006

10031007
@AllureFeatures.Fixtures

allure-testng/src/test/java/io/qameta/allure/testng/samples/CyrillicDescriptions.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,16 @@
2222
*/
2323
public class CyrillicDescriptions {
2424

25-
@Test(description = "Тест с описанием на русском языке")
25+
@Test(testName = "Тест с описанием на русском языке только в testName")
26+
public void testWithCyrillicTestName() throws Exception {
27+
}
28+
29+
@Test(description = "Тест с описанием на русском языке только в description")
2630
public void testWithCyrillicDescription() throws Exception {
2731
}
32+
33+
@Test(testName = "Тест с описанием на русском языке и в testName",
34+
description = "Тест с описанием на русском языке и в description")
35+
public void testWithCyrillicTestNameAndDescription() throws Exception {
36+
}
2837
}

0 commit comments

Comments
 (0)