mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
junit: compare suites by system.identityHashCode to avoid 'same parameter' problem (IDEA-142153)
This commit is contained in:
+35
@@ -151,6 +151,41 @@ public class JUnitTreeByDescriptionHierarchyTest {
|
||||
"##teamcity[testFinished name='TestA.testName|[1|]']\n" +
|
||||
"##teamcity[testSuiteFinished name='|[1|]']\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterizedClassWithSameParameters() throws Exception {
|
||||
final String className = "a.TestA";
|
||||
final Description aTestClassDescription = Description.createSuiteDescription(className);
|
||||
final ArrayList<Description> tests = new ArrayList<Description>();
|
||||
for (String paramName : new String[]{"[0]", "[0]"}) {
|
||||
final Description param1 = Description.createSuiteDescription(paramName);
|
||||
aTestClassDescription.addChild(param1);
|
||||
final Description testDescription = Description.createTestDescription(className, "testName" + paramName);
|
||||
tests.add(testDescription);
|
||||
param1.addChild(testDescription);
|
||||
}
|
||||
doTest(aTestClassDescription, tests,
|
||||
//tree
|
||||
"##teamcity[suiteTreeStarted name='|[0|]' locationHint='java:suite://a.TestA.|[0|]']\n" +
|
||||
"##teamcity[suiteTreeNode name='TestA.testName|[0|]' locationHint='java:test://a.TestA.testName|[0|]']\n" +
|
||||
"##teamcity[suiteTreeEnded name='|[0|]']\n" +
|
||||
"##teamcity[suiteTreeStarted name='|[0|]' locationHint='java:suite://a.TestA.|[0|]']\n" +
|
||||
"##teamcity[suiteTreeNode name='TestA.testName|[0|]' locationHint='java:test://a.TestA.testName|[0|]']\n" +
|
||||
"##teamcity[suiteTreeEnded name='|[0|]']\n",
|
||||
//start
|
||||
"##teamcity[enteredTheMatrix]\n" +
|
||||
"##teamcity[rootName name = 'TestA' comment = 'a' location = 'java:suite://a.TestA']\n" +
|
||||
"##teamcity[testSuiteStarted name='|[0|]']\n" +
|
||||
"##teamcity[testStarted name='TestA.testName|[0|]' locationHint='java:test://a.TestA.testName|[0|]']\n" +
|
||||
"\n" +
|
||||
"##teamcity[testFinished name='TestA.testName|[0|]']\n" +
|
||||
"##teamcity[testSuiteFinished name='|[0|]']\n" +
|
||||
"##teamcity[testSuiteStarted name='|[0|]']\n" +
|
||||
"##teamcity[testStarted name='TestA.testName|[0|]' locationHint='java:test://a.TestA.testName|[0|]']\n" +
|
||||
"\n" +
|
||||
"##teamcity[testFinished name='TestA.testName|[0|]']\n" +
|
||||
"##teamcity[testSuiteFinished name='|[0|]']\n");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2SuitesWithTheSameTest() throws Exception {
|
||||
|
||||
@@ -80,7 +80,7 @@ public class JUnit4TestListener extends RunListener {
|
||||
|
||||
public void testRunFinished(Result result) throws Exception {
|
||||
for (int i = myStartedSuites.size() - 1; i>= 0; i--) {
|
||||
Object parent = myStartedSuites.get(i);
|
||||
Object parent = JUnit4ReflectionUtil.getClassName((Description)myStartedSuites.get(i));
|
||||
myPrintStream.println("##teamcity[testSuiteFinished name=\'" + escapeName(getShortName((String)parent)) + "\']");
|
||||
}
|
||||
myStartedSuites.clear();
|
||||
@@ -92,29 +92,30 @@ public class JUnit4TestListener extends RunListener {
|
||||
final String classFQN = JUnit4ReflectionUtil.getClassName(description);
|
||||
|
||||
final List parents = (List)myParents.get(description);
|
||||
List parentsHierarchy = parents != null && !parents.isEmpty() ? (List)parents.remove(0) : Collections.singletonList(classFQN);
|
||||
List parentsHierarchy = parents != null && !parents.isEmpty() ? (List)parents.remove(0) : Collections.singletonList(description);
|
||||
|
||||
int idx = 0;
|
||||
String currentClass;
|
||||
String currentParent;
|
||||
Description currentClass;
|
||||
Description currentParent;
|
||||
while (idx < myStartedSuites.size() && idx < parentsHierarchy.size()) {
|
||||
currentClass = (String)myStartedSuites.get(idx);
|
||||
currentParent = (String)parentsHierarchy.get(parentsHierarchy.size() - 1 - idx);
|
||||
if (!currentClass.equals(currentParent)) break;
|
||||
currentClass = (Description)myStartedSuites.get(idx);
|
||||
currentParent = (Description)parentsHierarchy.get(parentsHierarchy.size() - 1 - idx);
|
||||
if (System.identityHashCode(currentClass) != System.identityHashCode(currentParent)) break;
|
||||
idx++;
|
||||
}
|
||||
|
||||
for (int i = myStartedSuites.size() - 1; i >= idx; i--) {
|
||||
currentClass = (String)myStartedSuites.remove(i);
|
||||
myPrintStream.println("##teamcity[testSuiteFinished name=\'" + escapeName(getShortName(currentClass)) + "\']");
|
||||
currentClass = (Description)myStartedSuites.remove(i);
|
||||
myPrintStream.println("##teamcity[testSuiteFinished name=\'" + escapeName(getShortName(JUnit4ReflectionUtil.getClassName(currentClass))) + "\']");
|
||||
}
|
||||
|
||||
for (int i = idx; i < parentsHierarchy.size(); i++) {
|
||||
final String fqName = (String) parentsHierarchy.get(parentsHierarchy.size() - 1 - i);
|
||||
final Description descriptionFromHistory = (Description)parentsHierarchy.get(parentsHierarchy.size() - 1 - i);
|
||||
final String fqName = JUnit4ReflectionUtil.getClassName(descriptionFromHistory);
|
||||
final String className = getShortName(fqName);
|
||||
if (!className.equals(myRootName)) {
|
||||
myPrintStream.println("##teamcity[testSuiteStarted name=\'" + escapeName(className) + "\'" + (parents == null ? " locationHint=\'java:suite://" + escapeName(fqName) + "\'" : "") + "]");
|
||||
myStartedSuites.add(fqName);
|
||||
myStartedSuites.add(descriptionFromHistory);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,7 +299,7 @@ public class JUnit4TestListener extends RunListener {
|
||||
if (parent != null) {
|
||||
final String parentClassName = JUnit4ReflectionUtil.getClassName(parent);
|
||||
if (!myRootName.equals(parentClassName)) {
|
||||
pParents.add(0, parentClassName);
|
||||
pParents.add(0, parent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user