Search in sources :

Example 6 with JUnit4TestListener

use of com.intellij.junit4.JUnit4TestListener in project intellij-community by JetBrains.

the class JUnitTreeByDescriptionHierarchyTest method testParallelExecution.

@Test
public void testParallelExecution() throws Exception {
    final Description root = Description.createSuiteDescription("root");
    Description testA = Description.createTestDescription("TestA", "test1");
    root.addChild(testA);
    Description testB = Description.createTestDescription("TestB", "test2");
    root.addChild(testB);
    final StringBuffer buf = new StringBuffer();
    final JUnit4TestListener sender = createListener(buf);
    sender.sendTree(root);
    Assert.assertEquals("output: " + buf, "##teamcity[enteredTheMatrix]\n" + "##teamcity[suiteTreeNode name='TestA.test1' locationHint='java:test://TestA.test1']\n" + "##teamcity[suiteTreeNode name='TestB.test2' locationHint='java:test://TestB.test2']\n" + "##teamcity[treeEnded]\n", StringUtil.convertLineSeparators(buf.toString()));
    buf.setLength(0);
    sender.testRunStarted(root);
    sender.testStarted(testA);
    sender.testStarted(testB);
    sender.testFinished(testB);
    final Exception exception = new Exception();
    exception.setStackTrace(new StackTraceElement[0]);
    sender.testFailure(new Failure(testA, exception));
    sender.testFinished(testA);
    sender.testRunFinished(new Result());
    Assert.assertEquals("output: " + buf, "##teamcity[rootName name = 'root' location = 'java:suite://root']\n" + "\n" + "##teamcity[testStarted name='TestA.test1' locationHint='java:test://TestA.test1']\n" + "\n" + "##teamcity[testFailed name='TestA.test1' details='java.lang.Exception|n' error='true' message='']\n" + "\n" + "##teamcity[testFinished name='TestA.test1']\n" + "\n" + "##teamcity[testStarted name='TestB.test2' locationHint='java:test://TestB.test2']\n" + "\n" + "##teamcity[testFinished name='TestB.test2']\n", StringUtil.convertLineSeparators(buf.toString()));
}
Also used : Description(org.junit.runner.Description) JUnit4TestListener(com.intellij.junit4.JUnit4TestListener) IOException(java.io.IOException) Failure(org.junit.runner.notification.Failure) ComparisonFailure(org.junit.ComparisonFailure) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 7 with JUnit4TestListener

use of com.intellij.junit4.JUnit4TestListener in project intellij-community by JetBrains.

the class JUnitTreeByDescriptionHierarchyTest method testSetupClassFailureForParameterizedClass.

@Test
public void testSetupClassFailureForParameterizedClass() throws Exception {
    final Description root = Description.createSuiteDescription("root");
    final Description testA = Description.createSuiteDescription("TestA");
    root.addChild(testA);
    final Description paramDescription = Description.createSuiteDescription("param");
    testA.addChild(paramDescription);
    final Description testName = Description.createTestDescription("TestA", "testName");
    paramDescription.addChild(testName);
    final StringBuffer buf = new StringBuffer();
    final JUnit4TestListener sender = createListener(buf);
    sender.sendTree(root);
    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" + "##teamcity[suiteTreeEnded name='TestA']\n" + "##teamcity[treeEnded]\n", StringUtil.convertLineSeparators(buf.toString()));
    buf.setLength(0);
    sender.testRunStarted(testA);
    final Exception exception = new Exception();
    exception.setStackTrace(new StackTraceElement[0]);
    sender.testAssumptionFailure(new Failure(testA, exception));
    sender.testRunFinished(new Result());
    Assert.assertEquals("output: " + buf, "##teamcity[rootName name = 'root' location = 'java:suite://root']\n" + "\n" + "##teamcity[testSuiteStarted name='TestA']\n" + "\n" + "##teamcity[testSuiteStarted name='param']\n" + "\n" + "##teamcity[testStarted name='TestA.testName' locationHint='java:test://TestA.testName']\n" + "\n" + "##teamcity[testIgnored name='TestA.testName' details='java.lang.Exception|n' error='true' message='']\n" + "\n" + "##teamcity[testFinished name='TestA.testName']\n" + "\n" + "##teamcity[testSuiteFinished name='param']\n" + "\n" + "##teamcity[testSuiteFinished name='TestA']\n", StringUtil.convertLineSeparators(buf.toString()));
    buf.setLength(0);
    //testStarted and testFinished are called by the framework
    sender.testRunStarted(testA);
    sender.testAssumptionFailure(new Failure(testName, exception));
    sender.testRunFinished(new Result());
    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()));
}
Also used : Description(org.junit.runner.Description) JUnit4TestListener(com.intellij.junit4.JUnit4TestListener) IOException(java.io.IOException) Failure(org.junit.runner.notification.Failure) ComparisonFailure(org.junit.ComparisonFailure) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 8 with JUnit4TestListener

use of com.intellij.junit4.JUnit4TestListener in project intellij-community by JetBrains.

the class JUnitTreeByDescriptionHierarchyTest method testSetupClassAssumptionFailure.

@Test
public void testSetupClassAssumptionFailure() throws Exception {
    final Description root = Description.createSuiteDescription("root");
    final Description testA = Description.createSuiteDescription("TestA");
    root.addChild(testA);
    final Description testName = Description.createTestDescription("TestA", "testName");
    testA.addChild(testName);
    final Description testB = Description.createSuiteDescription("TestB");
    root.addChild(testB);
    final Description testNameB = Description.createTestDescription("TestB", "testNameB");
    testB.addChild(testNameB);
    final StringBuffer buf = new StringBuffer();
    final JUnit4TestListener sender = createListener(buf);
    sender.sendTree(root);
    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[suiteTreeStarted name='TestB' locationHint='java:suite://TestB']\n" + "##teamcity[suiteTreeNode name='TestB.testNameB' locationHint='java:test://TestB.testNameB']\n" + "##teamcity[suiteTreeEnded name='TestB']\n" + "##teamcity[treeEnded]\n", StringUtil.convertLineSeparators(buf.toString()));
    buf.setLength(0);
    sender.testRunStarted(root);
    final Exception exception = new Exception();
    exception.setStackTrace(new StackTraceElement[0]);
    sender.testAssumptionFailure(new Failure(testA, exception));
    sender.testAssumptionFailure(new Failure(testB, exception));
    sender.testRunFinished(new Result());
    Assert.assertEquals("output: " + buf, "##teamcity[rootName name = 'root' location = 'java:suite://root']\n" + "\n" + "##teamcity[testSuiteStarted name='TestA']\n" + "\n" + "##teamcity[testStarted name='TestA.testName' locationHint='java:test://TestA.testName']\n" + "\n" + "##teamcity[testIgnored name='TestA.testName' details='java.lang.Exception|n' error='true' message='']\n" + "\n" + "##teamcity[testFinished name='TestA.testName']\n" + "\n" + "##teamcity[testSuiteFinished name='TestA']\n" + "\n" + "##teamcity[testSuiteStarted name='TestB']\n" + "\n" + "##teamcity[testStarted name='TestB.testNameB' locationHint='java:test://TestB.testNameB']\n" + "\n" + "##teamcity[testIgnored name='TestB.testNameB' details='java.lang.Exception|n' error='true' message='']\n" + "\n" + "##teamcity[testFinished name='TestB.testNameB']\n" + "\n" + "##teamcity[testSuiteFinished name='TestB']\n", StringUtil.convertLineSeparators(buf.toString()));
}
Also used : Description(org.junit.runner.Description) JUnit4TestListener(com.intellij.junit4.JUnit4TestListener) IOException(java.io.IOException) Failure(org.junit.runner.notification.Failure) ComparisonFailure(org.junit.ComparisonFailure) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 9 with JUnit4TestListener

use of com.intellij.junit4.JUnit4TestListener in project intellij-community by JetBrains.

the class JUnitTreeByDescriptionHierarchyTest method testAssumptionFailures.

@Test
public void testAssumptionFailures() throws Exception {
    Description root = Description.createSuiteDescription("root");
    for (int i = 0; i < 5; i++) {
        Description testClassDescription = Description.createSuiteDescription("Test" + i);
        root.addChild(testClassDescription);
        testClassDescription.addChild(Description.createTestDescription("Test" + i, "testName"));
    }
    final StringBuffer buf = new StringBuffer();
    final JUnit4TestListener sender = createListener(buf);
    sender.sendTree(root);
    Assert.assertEquals("output: " + buf, "##teamcity[enteredTheMatrix]\n" + "##teamcity[suiteTreeStarted name='Test0' locationHint='java:suite://Test0']\n" + "##teamcity[suiteTreeNode name='Test0.testName' locationHint='java:test://Test0.testName']\n" + "##teamcity[suiteTreeEnded name='Test0']\n" + "##teamcity[suiteTreeStarted name='Test1' locationHint='java:suite://Test1']\n" + "##teamcity[suiteTreeNode name='Test1.testName' locationHint='java:test://Test1.testName']\n" + "##teamcity[suiteTreeEnded name='Test1']\n" + "##teamcity[suiteTreeStarted name='Test2' locationHint='java:suite://Test2']\n" + "##teamcity[suiteTreeNode name='Test2.testName' locationHint='java:test://Test2.testName']\n" + "##teamcity[suiteTreeEnded name='Test2']\n" + "##teamcity[suiteTreeStarted name='Test3' locationHint='java:suite://Test3']\n" + "##teamcity[suiteTreeNode name='Test3.testName' locationHint='java:test://Test3.testName']\n" + "##teamcity[suiteTreeEnded name='Test3']\n" + "##teamcity[suiteTreeStarted name='Test4' locationHint='java:suite://Test4']\n" + "##teamcity[suiteTreeNode name='Test4.testName' locationHint='java:test://Test4.testName']\n" + "##teamcity[suiteTreeEnded name='Test4']\n" + "##teamcity[treeEnded]\n", StringUtil.convertLineSeparators(buf.toString()));
    buf.setLength(0);
    sender.testRunStarted(root);
    final Exception exception = new Exception();
    exception.setStackTrace(new StackTraceElement[0]);
    int idx = 0;
    for (Description description : root.getChildren()) {
        if (idx++ % 2 != 0) {
            sender.testAssumptionFailure(new Failure(description, exception));
        } else {
            for (Description testDescription : description.getChildren()) {
                sender.testStarted(testDescription);
                sender.testFinished(testDescription);
            }
        }
    }
    sender.testRunFinished(new Result());
    Assert.assertEquals("output: " + buf, "##teamcity[rootName name = 'root' location = 'java:suite://root']\n" + "\n" + "##teamcity[testSuiteStarted name='Test0']\n" + "\n" + "##teamcity[testStarted name='Test0.testName' locationHint='java:test://Test0.testName']\n" + "\n" + "##teamcity[testFinished name='Test0.testName']\n" + "\n" + "##teamcity[testSuiteFinished name='Test0']\n" + "\n" + "##teamcity[testSuiteStarted name='Test1']\n" + "\n" + "##teamcity[testStarted name='Test1.testName' locationHint='java:test://Test1.testName']\n" + "\n" + "##teamcity[testIgnored name='Test1.testName' details='java.lang.Exception|n' error='true' message='']\n" + "\n" + "##teamcity[testFinished name='Test1.testName']\n" + "\n" + "##teamcity[testSuiteFinished name='Test1']\n" + "\n" + "##teamcity[testSuiteStarted name='Test2']\n" + "\n" + "##teamcity[testStarted name='Test2.testName' locationHint='java:test://Test2.testName']\n" + "\n" + "##teamcity[testFinished name='Test2.testName']\n" + "\n" + "##teamcity[testSuiteFinished name='Test2']\n" + "\n" + "##teamcity[testSuiteStarted name='Test3']\n" + "\n" + "##teamcity[testStarted name='Test3.testName' locationHint='java:test://Test3.testName']\n" + "\n" + "##teamcity[testIgnored name='Test3.testName' details='java.lang.Exception|n' error='true' message='']\n" + "\n" + "##teamcity[testFinished name='Test3.testName']\n" + "\n" + "##teamcity[testSuiteFinished name='Test3']\n" + "\n" + "##teamcity[testSuiteStarted name='Test4']\n" + "\n" + "##teamcity[testStarted name='Test4.testName' locationHint='java:test://Test4.testName']\n" + "\n" + "##teamcity[testFinished name='Test4.testName']\n" + "\n" + "##teamcity[testSuiteFinished name='Test4']\n", StringUtil.convertLineSeparators(buf.toString()));
}
Also used : Description(org.junit.runner.Description) JUnit4TestListener(com.intellij.junit4.JUnit4TestListener) IOException(java.io.IOException) Failure(org.junit.runner.notification.Failure) ComparisonFailure(org.junit.ComparisonFailure) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 10 with JUnit4TestListener

use of com.intellij.junit4.JUnit4TestListener in project intellij-community by JetBrains.

the class JUnitTreeByDescriptionHierarchyTest method testSetupClassFailure.

@Test
public void testSetupClassFailure() throws Exception {
    final Description root = Description.createSuiteDescription("root");
    final Description testA = Description.createSuiteDescription("TestA");
    root.addChild(testA);
    final Description testName = Description.createTestDescription("TestA", "testName");
    testA.addChild(testName);
    final StringBuffer buf = new StringBuffer();
    final JUnit4TestListener sender = createListener(buf);
    sender.sendTree(root);
    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()));
    buf.setLength(0);
    sender.testRunStarted(testA);
    final Exception exception = new Exception();
    exception.setStackTrace(new StackTraceElement[0]);
    sender.testFailure(new Failure(testA, exception));
    sender.testRunFinished(new Result());
    Assert.assertEquals("output: " + buf, "##teamcity[rootName name = 'root' location = 'java:suite://root']\n" + "\n" + "##teamcity[testStarted name='Class Configuration'  locationHint='java:suite://TestA' ]\n" + "\n" + "##teamcity[testFailed name='Class Configuration' details='java.lang.Exception|n' error='true' message='']\n" + "\n" + "##teamcity[testFinished name='Class Configuration']\n" + "\n" + "##teamcity[testSuiteStarted name='TestA']\n" + "\n" + "##teamcity[testStarted name='TestA.testName' locationHint='java:test://TestA.testName']\n" + "\n" + "##teamcity[testIgnored name='TestA.testName']\n" + "\n" + "##teamcity[testFinished name='TestA.testName']\n" + "\n" + "##teamcity[testSuiteFinished name='TestA']\n", StringUtil.convertLineSeparators(buf.toString()));
}
Also used : Description(org.junit.runner.Description) JUnit4TestListener(com.intellij.junit4.JUnit4TestListener) IOException(java.io.IOException) Failure(org.junit.runner.notification.Failure) ComparisonFailure(org.junit.ComparisonFailure) Result(org.junit.runner.Result) Test(org.junit.Test)

Aggregations

JUnit4TestListener (com.intellij.junit4.JUnit4TestListener)10 Description (org.junit.runner.Description)10 Test (org.junit.Test)9 Result (org.junit.runner.Result)9 ComparisonFailure (org.junit.ComparisonFailure)7 Failure (org.junit.runner.notification.Failure)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)2