testng: keep initial invocation numbers when rerun failed (IDEA-156780)

This commit is contained in:
Anna.Kozlova
2017-04-20 17:40:02 +02:00
parent 4eac2f3550
commit bbd9357777
2 changed files with 60 additions and 3 deletions
@@ -293,6 +293,37 @@ public class TestNGTreeHierarchyTest {
"##teamcity[testFinished name='ATest.testMe|[null, null|]']\n", StringUtil.convertLineSeparators(buf.toString()));
}
@Test
public void testIncludedMethods() throws Exception {
final StringBuffer buf = new StringBuffer();
final IDEATestNGRemoteListener listener = createListener(buf);
final MockTestNGResult result = new MockTestNGResult("ATest", "testMe", null, new Object[]{null, null}) {
@Override
public List<Integer> getIncludeMethods() {
return Arrays.asList(1, 3, 5);
}
};
for (int i = 0; i < 3; i++) {
listener.onTestStart(result);
listener.onTestFinished(result);
}
Assert.assertEquals("output: " + buf, "##teamcity[enteredTheMatrix]\n" +
"\n" +
"##teamcity[testSuiteStarted name ='ATest' locationHint = 'java:suite://ATest']\n" +
"\n" +
"##teamcity[testStarted name='ATest.testMe|[null, null|] (1)' locationHint='java:test://ATest.testMe|[1|]']\n" +
"\n" +
"##teamcity[testFinished name='ATest.testMe|[null, null|] (1)']\n" +
"\n" +
"##teamcity[testStarted name='ATest.testMe|[null, null|] (3)' locationHint='java:test://ATest.testMe|[3|]']\n" +
"\n" +
"##teamcity[testFinished name='ATest.testMe|[null, null|] (3)']\n" +
"\n" +
"##teamcity[testStarted name='ATest.testMe|[null, null|] (5)' locationHint='java:test://ATest.testMe|[5|]']\n" +
"\n" +
"##teamcity[testFinished name='ATest.testMe|[null, null|] (5)']\n", StringUtil.convertLineSeparators(buf.toString()));
}
private static void doTest(XmlSuite suite, String expected) {
final StringBuffer buf = new StringBuffer();
final IDEATestNGRemoteListener listener = createListener(buf);
@@ -401,6 +432,11 @@ public class TestNGTreeHierarchyTest {
return myThrowable;
}
@Override
public List<Integer> getIncludeMethods() {
return null;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
@@ -1,6 +1,8 @@
package org.testng;
import com.intellij.rt.execution.junit.ComparisonFailureData;
import org.testng.xml.XmlClass;
import org.testng.xml.XmlInclude;
import org.testng.xml.XmlTest;
import java.io.PrintStream;
@@ -130,12 +132,20 @@ public class IDEATestNGRemoteListener {
if (invocationCount == null) {
invocationCount = 0;
}
final String paramString = getParamsString(parameters, invocationCount);
onTestStart(result, paramString, invocationCount, false);
Integer normalizedIndex = normalizeInvocationCountInsideIncludedMethods(invocationCount, result);
final String paramString = getParamsString(parameters, normalizedIndex);
onTestStart(result, paramString, normalizedIndex, false);
myInvocationCounts.put(qualifiedName, invocationCount + 1);
}
private static Integer normalizeInvocationCountInsideIncludedMethods(Integer invocationCount, ExposedTestResult result) {
List<Integer> includeMethods = result.getIncludeMethods();
if (includeMethods == null || invocationCount >= includeMethods.size()) {
return invocationCount;
}
return includeMethods.get(invocationCount);
}
public void onConfigurationStart(ExposedTestResult result) {
onTestStart(result, null, -1, true);
}
@@ -296,6 +306,7 @@ public class IDEATestNGRemoteListener {
String getFileName();
String getXmlTestName();
Throwable getThrowable();
List<Integer> getIncludeMethods();
}
protected DelegatedResult createDelegated(ITestResult result) {
@@ -363,6 +374,16 @@ public class IDEATestNGRemoteListener {
return myResult.getThrowable();
}
public List<Integer> getIncludeMethods() {
IClass testClass = myResult.getTestClass();
if (testClass == null) return null;
XmlClass xmlClass = testClass.getXmlClass();
if (xmlClass == null) return null;
List<XmlInclude> includedMethods = xmlClass.getIncludedMethods();
if (includedMethods.isEmpty()) return null;
return includedMethods.get(0).getInvocationNumbers();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;