junit/testng: attach listener before test run so suggestion to change module would work (IDEA-145050)

This commit is contained in:
Anna Kozlova
2015-09-11 19:56:45 +03:00
parent b0d45cd4be
commit 9bbc955f94
4 changed files with 35 additions and 31 deletions
@@ -33,7 +33,8 @@ import java.util.List;
public class JUnitTreeByDescriptionHierarchyTest {
@Test
public void testEmptySuite() throws Exception {
doTest(Description.createSuiteDescription("empty suite"), "##teamcity[treeEnded]\n");
doTest(Description.createSuiteDescription("empty suite"), "##teamcity[enteredTheMatrix]\n" +
"##teamcity[treeEnded]\n");
}
@Test
@@ -46,6 +47,7 @@ public class JUnitTreeByDescriptionHierarchyTest {
attachParameterizedTests(className, aTestClass, tests);
}
doTest(root, tests,
"##teamcity[enteredTheMatrix]\n" +
"##teamcity[suiteTreeStarted name='TestA' locationHint='java:suite://a.TestA']\n" +
"##teamcity[suiteTreeStarted name='|[0|]' locationHint='java:suite://a.TestA.|[0|]']\n" +
"##teamcity[suiteTreeNode name='testName|[0|]' locationHint='java:test://a.TestA.testName|[0|]']\n" +
@@ -65,7 +67,6 @@ public class JUnitTreeByDescriptionHierarchyTest {
"##teamcity[treeEnded]\n",
"##teamcity[enteredTheMatrix]\n" +
"##teamcity[rootName name = 'root' location = 'java:suite://root']\n" +
"##teamcity[testSuiteStarted name='TestA']\n" +
"##teamcity[testSuiteStarted name='|[0|]']\n" +
@@ -135,14 +136,14 @@ public class JUnitTreeByDescriptionHierarchyTest {
tests.add(testDescription);
aTestClass.addChild(testDescription);
}
doTest(rootDescription, tests, "##teamcity[suiteTreeStarted name='MyTest' locationHint='java:suite://a.MyTest']\n" +
doTest(rootDescription, tests, "##teamcity[enteredTheMatrix]\n" +
"##teamcity[suiteTreeStarted name='MyTest' locationHint='java:suite://a.MyTest']\n" +
"##teamcity[suiteTreeNode name='MyTest.testMe' locationHint='java:test://a.MyTest.testMe']\n" +
"##teamcity[suiteTreeEnded name='MyTest']\n" +
"##teamcity[suiteTreeStarted name='MyTest' locationHint='java:suite://b.MyTest']\n" +
"##teamcity[suiteTreeNode name='MyTest.testMe' locationHint='java:test://b.MyTest.testMe']\n" +
"##teamcity[suiteTreeEnded name='MyTest']\n" +
"##teamcity[treeEnded]\n",
"##teamcity[enteredTheMatrix]\n" +
"##teamcity[rootName name = 'root' location = 'java:suite://root']\n" +
"##teamcity[testSuiteStarted name='MyTest']\n" +
"##teamcity[testStarted name='MyTest.testMe' locationHint='java:test://a.MyTest.testMe']\n" +
@@ -165,6 +166,7 @@ public class JUnitTreeByDescriptionHierarchyTest {
attachParameterizedTests(className, aTestClassDescription, tests);
doTest(aTestClassDescription, tests,
//tree
"##teamcity[enteredTheMatrix]\n" +
"##teamcity[suiteTreeStarted name='|[0|]' locationHint='java:suite://a.TestA.|[0|]']\n" +
"##teamcity[suiteTreeNode name='testName|[0|]' locationHint='java:test://a.TestA.testName|[0|]']\n" +
"##teamcity[suiteTreeEnded name='|[0|]']\n" +
@@ -173,7 +175,6 @@ public class JUnitTreeByDescriptionHierarchyTest {
"##teamcity[suiteTreeEnded name='|[1|]']\n" +
"##teamcity[treeEnded]\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='testName|[0|]' locationHint='java:test://a.TestA.testName|[0|]']\n" +
@@ -201,6 +202,7 @@ public class JUnitTreeByDescriptionHierarchyTest {
}
doTest(aTestClassDescription, tests,
//tree
"##teamcity[enteredTheMatrix]\n" +
"##teamcity[suiteTreeStarted name='|[0|]' locationHint='java:suite://a.TestA.|[0|]']\n" +
"##teamcity[suiteTreeNode name='testName|[0|]' locationHint='java:test://a.TestA.testName|[0|]']\n" +
"##teamcity[suiteTreeEnded name='|[0|]']\n" +
@@ -209,7 +211,6 @@ public class JUnitTreeByDescriptionHierarchyTest {
"##teamcity[suiteTreeEnded name='|[0|]']\n" +
"##teamcity[treeEnded]\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='testName|[0|]' locationHint='java:test://a.TestA.testName|[0|]']\n" +
@@ -237,6 +238,7 @@ public class JUnitTreeByDescriptionHierarchyTest {
}
doTest(aTestClassDescription, tests,
//tree
"##teamcity[enteredTheMatrix]\n" +
"##teamcity[suiteTreeStarted name='|[0: with - 1.1|]' locationHint='java:suite://a.TestA.|[0: with - 1.1|]']\n" +
"##teamcity[suiteTreeNode name='testName|[0: with - 1.1|]' locationHint='java:test://a.TestA.testName|[0: with - 1.1|]']\n" +
"##teamcity[suiteTreeEnded name='|[0: with - 1.1|]']\n" +
@@ -245,7 +247,6 @@ public class JUnitTreeByDescriptionHierarchyTest {
"##teamcity[suiteTreeEnded name='|[1: with - 2.1|]']\n" +
"##teamcity[treeEnded]\n",
//start
"##teamcity[enteredTheMatrix]\n" +
"##teamcity[rootName name = 'TestA' comment = 'a' location = 'java:suite://a.TestA']\n" +
"##teamcity[testSuiteStarted name='|[0: with - 1.1|]']\n" +
"##teamcity[testStarted name='testName|[0: with - 1.1|]' locationHint='java:test://a.TestA.testName|[0: with - 1.1|]']\n" +
@@ -277,6 +278,7 @@ public class JUnitTreeByDescriptionHierarchyTest {
doTest(root, tests,
//expected tree
"##teamcity[enteredTheMatrix]\n" +
"##teamcity[suiteTreeStarted name='ASuite1' locationHint='java:suite://ASuite1']\n" +
"##teamcity[suiteTreeStarted name='ATest' locationHint='java:suite://ATest']\n" +
"##teamcity[suiteTreeNode name='ATest.test1' locationHint='java:test://ATest.test1']\n" +
@@ -290,7 +292,6 @@ public class JUnitTreeByDescriptionHierarchyTest {
"##teamcity[treeEnded]\n",
//started
"##teamcity[enteredTheMatrix]\n" +
"##teamcity[rootName name = 'root' location = 'java:suite://root']\n" +
"##teamcity[testSuiteStarted name='ASuite1']\n" +
"##teamcity[testSuiteStarted name='ATest']\n" +
@@ -339,7 +340,8 @@ public class JUnitTreeByDescriptionHierarchyTest {
final JUnit4TestListener sender = createListener(buf);
sender.sendTree(root);
Assert.assertEquals("output: " + buf, "##teamcity[suiteTreeStarted name='TestA' locationHint='java:suite://TestA']\n" +
Assert.assertEquals("output: " + buf, "##teamcity[enteredTheMatrix]\n" +
"##teamcity[suiteTreeStarted name='TestA' locationHint='java:suite://TestA']\n" +
"##teamcity[suiteTreeNode name='TestA.testName' locationHint='java:test://TestA.testName']\n" +
"##teamcity[suiteTreeEnded name='TestA']\n" +
"##teamcity[treeEnded]\n", StringUtil.convertLineSeparators(buf.toString()));
@@ -352,8 +354,7 @@ public class JUnitTreeByDescriptionHierarchyTest {
sender.testAssumptionFailure(new Failure(testA, exception));
sender.testRunFinished(new Result());
Assert.assertEquals("output: " + buf, "##teamcity[enteredTheMatrix]\n" +
"##teamcity[rootName name = 'root' location = 'java:suite://root']\n" +
Assert.assertEquals("output: " + buf, "##teamcity[rootName name = 'root' location = 'java:suite://root']\n" +
"##teamcity[testSuiteStarted name='TestA']\n" +
"##teamcity[testStarted name='TestA.testName' locationHint='java:test://TestA.testName']\n" +
"\n" +
@@ -377,7 +378,8 @@ public class JUnitTreeByDescriptionHierarchyTest {
final JUnit4TestListener sender = createListener(buf);
sender.sendTree(root);
Assert.assertEquals("output: " + buf, "##teamcity[suiteTreeStarted name='TestA' locationHint='java:suite://TestA']\n" +
Assert.assertEquals("output: " + buf, "##teamcity[enteredTheMatrix]\n" +
"##teamcity[suiteTreeStarted name='TestA' locationHint='java:suite://TestA']\n" +
"##teamcity[suiteTreeStarted name='param' locationHint='java:suite://param']\n" +
"##teamcity[suiteTreeNode name='TestA.testName' locationHint='java:test://TestA.testName']\n" +
"##teamcity[suiteTreeEnded name='param']\n" +
@@ -392,8 +394,7 @@ public class JUnitTreeByDescriptionHierarchyTest {
sender.testAssumptionFailure(new Failure(testA, exception));
sender.testRunFinished(new Result());
Assert.assertEquals("output: " + buf, "##teamcity[enteredTheMatrix]\n" +
"##teamcity[rootName name = 'root' location = 'java:suite://root']\n" +
Assert.assertEquals("output: " + buf, "##teamcity[rootName name = 'root' location = 'java:suite://root']\n" +
"##teamcity[testSuiteStarted name='TestA']\n" +
"##teamcity[testSuiteStarted name='param']\n" +
"##teamcity[testStarted name='TestA.testName' locationHint='java:test://TestA.testName']\n" +
@@ -410,8 +411,7 @@ public class JUnitTreeByDescriptionHierarchyTest {
sender.testAssumptionFailure(new Failure(testName, exception));
sender.testRunFinished(new Result());
Assert.assertEquals("output: " + buf, "##teamcity[enteredTheMatrix]\n" +
"##teamcity[rootName name = 'root' location = 'java:suite://root']\n" +
Assert.assertEquals("output: " + buf, "##teamcity[rootName name = 'root' location = 'java:suite://root']\n" +
"\n" +
"##teamcity[testIgnored name='TestA.testName' details='java.lang.Exception|n' error='true' message='']\n", StringUtil.convertLineSeparators(buf.toString()));
@@ -420,10 +420,10 @@ public class JUnitTreeByDescriptionHierarchyTest {
@Test
public void testSingleMethod() throws Exception {
final Description rootDescription = Description.createTestDescription("TestA", "testName");
doTest(rootDescription, Collections.singletonList(rootDescription),
doTest(rootDescription, Collections.singletonList(rootDescription),
"##teamcity[enteredTheMatrix]\n" +
"##teamcity[suiteTreeNode name='TestA.testName' locationHint='java:test://TestA.testName']\n" +
"##teamcity[treeEnded]\n",
"##teamcity[enteredTheMatrix]\n" +
"##teamcity[rootName name = 'TestA' location = 'java:suite://TestA']\n" +
"##teamcity[testStarted name='TestA.testName' locationHint='java:test://TestA.testName']\n" +
"\n" +
@@ -496,6 +496,7 @@ public class JUnitTreeByDescriptionHierarchyTest {
testMethod.addChild(testDescription);
}
doTest(aTestClass, tests,
"##teamcity[enteredTheMatrix]\n" +
"##teamcity[suiteTreeStarted name='testName' locationHint='java:suite://testName']\n" +
"##teamcity[suiteTreeNode name='ATest.testName|[0|]' locationHint='java:test://ATest.testName|[0|]']\n" +
"##teamcity[suiteTreeNode name='ATest.testName|[1|]' locationHint='java:test://ATest.testName|[1|]']\n" +
@@ -503,7 +504,6 @@ public class JUnitTreeByDescriptionHierarchyTest {
"##teamcity[treeEnded]\n",
"##teamcity[enteredTheMatrix]\n" +
"##teamcity[rootName name = 'ATest' location = 'java:suite://ATest']\n" +
"##teamcity[testSuiteStarted name='testName']\n" +
"##teamcity[testStarted name='ATest.testName|[0|]' locationHint='java:test://ATest.testName|[0|]']\n" +
@@ -530,6 +530,7 @@ public class JUnitTreeByDescriptionHierarchyTest {
aTestClassWithJUnit3Test.addChild(testDescription);
tests.add(testDescription);
doTest(root, tests,
"##teamcity[enteredTheMatrix]\n" +
"##teamcity[suiteTreeStarted name='ATest' locationHint='java:suite://ATest']\n" +
"##teamcity[suiteTreeStarted name='|[0|]' locationHint='java:suite://ATest.|[0|]']\n" +
"##teamcity[suiteTreeNode name='testName|[0|]' locationHint='java:test://ATest.testName|[0|]']\n" +
@@ -546,7 +547,6 @@ public class JUnitTreeByDescriptionHierarchyTest {
"##teamcity[treeEnded]\n",
//start
"##teamcity[enteredTheMatrix]\n" +
"##teamcity[rootName name = 'root' location = 'java:suite://root']\n" +
"##teamcity[testSuiteStarted name='ATest']\n" +
"##teamcity[testSuiteStarted name='|[0|]']\n" +
@@ -593,11 +593,10 @@ public class JUnitTreeByDescriptionHierarchyTest {
final Description emptyDescription = Description.createTestDescription(JUnit4TestListener.EMPTY_SUITE_NAME, JUnit4TestListener.EMPTY_SUITE_WARNING);
description.addChild(emptyDescription);
doTest(description, Collections.singletonList(emptyDescription),
"##teamcity[enteredTheMatrix]\n" +
"##teamcity[suiteTreeNode name='TestSuite$1.warning' locationHint='java:test://junit.framework.TestSuite$1.warning']\n" +
"##teamcity[treeEnded]\n",
"##teamcity[enteredTheMatrix]\n" +
"##teamcity[rootName name = 'TestA' location = 'java:suite://TestA']\n" +
"##teamcity[testStarted name='TestSuite$1.warning' locationHint='java:test://junit.framework.TestSuite$1.warning']\n" +
"\n" +
@@ -50,11 +50,12 @@ public class JUnit4TestListener extends RunListener {
private long myCurrentTestStart;
public JUnit4TestListener() {
myPrintStream = System.out;
this(System.out);
}
public JUnit4TestListener(PrintStream printStream) {
myPrintStream = printStream;
myPrintStream.println("##teamcity[enteredTheMatrix]");
}
private static String escapeName(String str) {
@@ -62,7 +63,6 @@ public class JUnit4TestListener extends RunListener {
}
public void testRunStarted(Description description) throws Exception {
myPrintStream.println("##teamcity[enteredTheMatrix]");
if (myRootName != null && !myRootName.startsWith("[")) {
int lastPointIdx = myRootName.lastIndexOf('.');
String name = myRootName;
@@ -46,7 +46,8 @@ public class TestNGTreeHierarchyTest {
test.getClasses().add(xmlClass);
suite.getTests().add(test);
doTest(suite, "\n" +
doTest(suite,"##teamcity[enteredTheMatrix]\n" +
"\n" +
"##teamcity[testSuiteStarted name ='ATest' locationHint = 'java:suite://a.ATest']\n" +
"\n" +
"##teamcity[testStarted name='ATest.test1|[0|]' locationHint='java:test://a.ATest.test1|[0|]']\n" +
@@ -187,7 +188,8 @@ public class TestNGTreeHierarchyTest {
test.getClasses().add(xmlClass);
suite.getTests().add(test);
doTest(suite, "\n" +
doTest(suite, "##teamcity[enteredTheMatrix]\n" +
"\n" +
"##teamcity[testSuiteStarted name ='ATest' locationHint = 'java:suite://a.ATest']\n" +
"\n" +
"##teamcity[testStarted name='ATest.test1|[0|]' locationHint='java:test://a.ATest.test1|[0|]']\n" +
@@ -222,7 +224,8 @@ public class TestNGTreeHierarchyTest {
}
listener.onSuiteFinish(className);
Assert.assertEquals("output: " + buf, "\n" +
Assert.assertEquals("output: " + buf,"##teamcity[enteredTheMatrix]\n" +
"\n" +
"##teamcity[testSuiteStarted name ='ATest' locationHint = 'java:suite://a.ATest']\n" +
"\n" +
"##teamcity[testStarted name='ATest.setUp' locationHint='java:test://a.ATest.setUp' config='true']\n" +
@@ -262,7 +265,8 @@ public class TestNGTreeHierarchyTest {
listener.onConfigurationFailure(setUp);
listener.onSuiteFinish(className);
Assert.assertEquals("output: " + buf, "\n" +
Assert.assertEquals("output: " + buf, "##teamcity[enteredTheMatrix]\n" +
"\n" +
"##teamcity[testSuiteStarted name ='ATest' locationHint = 'java:suite://a.ATest']\n" +
"\n" +
"##teamcity[testStarted name='ATest.setUp' locationHint='java:test://a.ATest.setUp' config='true']\n" +
@@ -279,7 +283,8 @@ public class TestNGTreeHierarchyTest {
final MockTestNGResult result = new MockTestNGResult("ATest", "testMe", null, new Object[]{null, null});
listener.onTestStart(result);
listener.onTestFinished(result);
Assert.assertEquals("output: " + buf, "\n" +
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|]' locationHint='java:test://ATest.testMe|[0|]']\n" +
@@ -21,15 +21,15 @@ public class IDEATestNGRemoteListener implements ISuiteListener, IResultListener
private final Map<ExposedTestResult, String> myParamsMap = new HashMap<ExposedTestResult, String>();
public IDEATestNGRemoteListener() {
myPrintStream = System.out;
this(System.out);
}
public IDEATestNGRemoteListener(PrintStream printStream) {
myPrintStream = printStream;
myPrintStream.println("##teamcity[enteredTheMatrix]");
}
public synchronized void onStart(final ISuite suite) {
myPrintStream.println("##teamcity[enteredTheMatrix]");
if (suite != null) {
final List<ITestNGMethod> allMethods = suite.getAllMethods();
if (allMethods != null) {