Skip to content

[TestNG] Lookup test name for report first in 'testName' field inside 'Test' annotation #1154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -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;
Expand Down Expand Up @@ -811,6 +812,7 @@ private List<Parameter> getParameters(final ITestContext context,

private String getMethodName(final ITestNGMethod method) {
return firstNonEmpty(
getTestNameFromAnnotation(method),
method.getDescription(),
method.getMethodName(),
getQualifiedName(method)).orElse("Unknown");
Expand Down Expand Up @@ -881,6 +883,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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,11 @@ public void shouldProcessCyrillicDescriptions() {

assertThat(results.getTestResults())
.extracting(TestResult::getName)
.containsExactlyInAnyOrder("Тест с описанием на русском языке");
.contains(
"Тест с описанием на русском языке только в testName",
"Тест с описанием на русском языке только в description",
"Тест с описанием на русском языке и в testName"
);
}

@AllureFeatures.Fixtures
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}
}
Loading