mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
testng: testName reported in test tree is wrong IDEA-208083
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package org.testng;
|
||||
|
||||
import com.intellij.rt.execution.junit.ComparisonFailureData;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.internal.ConstructorOrMethod;
|
||||
import org.testng.xml.XmlClass;
|
||||
import org.testng.xml.XmlInclude;
|
||||
import org.testng.xml.XmlTest;
|
||||
@@ -8,6 +10,7 @@ import org.testng.xml.XmlTest;
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.reflect.AccessibleObject;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
|
||||
@@ -354,7 +357,29 @@ public class IDEATestNGRemoteListener {
|
||||
|
||||
public DelegatedResult(ITestResult result) {
|
||||
myResult = result;
|
||||
myTestName = myResult.getTestName();
|
||||
myTestName = calculateDisplayName();
|
||||
}
|
||||
|
||||
//workaround for https://github.com/cbeust/testng/issues/1944
|
||||
private String calculateDisplayName() {
|
||||
String name = myResult.getTestName();
|
||||
if (name != null && !name.equals(myResult.getTestClass().getTestName())) {
|
||||
return name;
|
||||
}
|
||||
ITestNGMethod method = myResult.getMethod();
|
||||
ConstructorOrMethod constructorOrMethod = method.getConstructorOrMethod();
|
||||
AccessibleObject member = null;
|
||||
if (constructorOrMethod.getMethod() != null) {
|
||||
member = constructorOrMethod.getMethod();
|
||||
}
|
||||
if (constructorOrMethod.getConstructor() != null) {
|
||||
member = constructorOrMethod.getConstructor();
|
||||
}
|
||||
if (member == null) return method.getMethodName();
|
||||
Test annotation = member.getAnnotation(Test.class);
|
||||
if (annotation == null) return method.getMethodName();
|
||||
String testNameFromAnnotation = annotation.testName();
|
||||
return testNameFromAnnotation == null || testNameFromAnnotation.length() == 0 ? method.getMethodName() : testNameFromAnnotation;
|
||||
}
|
||||
|
||||
public Object[] getParameters() {
|
||||
@@ -366,7 +391,7 @@ public class IDEATestNGRemoteListener {
|
||||
}
|
||||
|
||||
public String getDisplayMethodName() {
|
||||
return myTestName != null && myTestName.length() > 0 ? myTestName : myResult.getMethod().getMethodName();
|
||||
return myTestName;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
|
||||
+6
-4
@@ -6,7 +6,6 @@ import com.intellij.java.execution.AbstractTestFrameworkCompilingIntegrationTest
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.testFramework.EdtRule;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
@@ -24,6 +23,7 @@ import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RunsInEdt
|
||||
@RunWith(Parameterized.class)
|
||||
@@ -84,12 +84,14 @@ public class TestNGIntegrationTest extends AbstractTestFrameworkCompilingIntegra
|
||||
public void simpleStart() throws ExecutionException {
|
||||
PsiClass psiClass = findClass(myModule, "a.Test1");
|
||||
assertNotNull(psiClass);
|
||||
PsiMethod testMethod = psiClass.findMethodsByName("simple", false)[0];
|
||||
TestNGConfiguration configuration = createConfiguration(testMethod);
|
||||
TestNGConfiguration configuration = createConfiguration(psiClass);
|
||||
ProcessOutput processOutput = doStartTestsProcess(configuration);
|
||||
String testOutput = processOutput.out.toString();
|
||||
assertEmpty(processOutput.err);
|
||||
assertTrue(testOutput, testOutput.contains("sample output"));
|
||||
}
|
||||
|
||||
String messages = processOutput.messages.stream().map(m -> m.asString()).collect(Collectors.joining("\n"));
|
||||
assertTrue(messages, messages.contains("name='Test1.myName'"));
|
||||
assertTrue(messages, messages.contains("name='Test1.simple2'"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
package a;
|
||||
|
||||
public class Test1 {
|
||||
@org.testng.annotations.Test
|
||||
@org.testng.annotations.Test(testName = "myName")
|
||||
public void simple() {
|
||||
System.out.println("sample output");
|
||||
}
|
||||
|
||||
@org.testng.annotations.Test
|
||||
public void simple2() {
|
||||
System.out.println("sample output");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user