Search in sources :

Example 1 with JUnit4TestListener

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

the class JUnitTreeByDescriptionHierarchyTest method doTest.

private static void doTest(Description root, List<Description> tests, String expectedTree, String expectedStart) throws Exception {
    final StringBuffer buf = new StringBuffer();
    final JUnit4TestListener sender = createListener(buf);
    sender.sendTree(root);
    Assert.assertEquals("output: " + buf, expectedTree, StringUtil.convertLineSeparators(buf.toString()));
    buf.setLength(0);
    sender.testRunStarted(root);
    for (Description test : tests) {
        sender.testStarted(test);
        sender.testFinished(test);
    }
    sender.testRunFinished(new Result());
    Assert.assertEquals("output: " + buf, expectedStart, StringUtil.convertLineSeparators(buf.toString()));
}
Also used : Description(org.junit.runner.Description) JUnit4TestListener(com.intellij.junit4.JUnit4TestListener) Result(org.junit.runner.Result)

Example 2 with JUnit4TestListener

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

the class JUnitTreeByDescriptionHierarchyTest method testLongOutputPreservesTestName.

@Test
public void testLongOutputPreservesTestName() throws Exception {
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < 1000; i++) {
        buf.append(DebugUtil.currentStackTrace());
    }
    final StringBuffer output = new StringBuffer();
    final JUnit4TestListener sender = createListener(output);
    final Description description = Description.createTestDescription("A", "a");
    sender.testFailure(new Failure(description, new ComparisonFailure(buf.toString(), buf.toString(), "diff" + buf.toString())));
    final String startMessage = "##teamcity[enteredTheMatrix]\n\n" + "##teamcity[testFailed name='A.a' ";
    assertEquals(startMessage, StringUtil.convertLineSeparators(output.toString()).substring(0, startMessage.length()));
}
Also used : Description(org.junit.runner.Description) ComparisonFailure(org.junit.ComparisonFailure) JUnit4TestListener(com.intellij.junit4.JUnit4TestListener) Failure(org.junit.runner.notification.Failure) ComparisonFailure(org.junit.ComparisonFailure) Test(org.junit.Test)

Example 3 with JUnit4TestListener

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

the class JUnitTreeByDescriptionHierarchyTest method testPackageWithoutDescriptionBefore.

@Test
public void testPackageWithoutDescriptionBefore() throws Exception {
    final Description root = Description.createSuiteDescription("root");
    final ArrayList<Description> tests = new ArrayList<>();
    for (String className : new String[] { "a.TestA", "a.TestB" }) {
        final Description aTestClass = Description.createSuiteDescription(className);
        root.addChild(aTestClass);
        final Description testDescription = Description.createTestDescription(className, "testName");
        aTestClass.addChild(testDescription);
        tests.add(testDescription);
    }
    final StringBuffer buf = new StringBuffer();
    final JUnit4TestListener sender = createListener(buf);
    sender.testRunStarted(root);
    for (Description test : tests) {
        sender.testStarted(test);
        sender.testFinished(test);
    }
    sender.testRunFinished(new Result());
    Assert.assertEquals("output: " + buf, "##teamcity[enteredTheMatrix]\n" + "\n" + "##teamcity[testSuiteStarted name='TestA' locationHint='java:suite://a.TestA']\n" + "\n" + "##teamcity[testStarted name='TestA.testName' locationHint='java:test://a.TestA.testName']\n" + "\n" + "##teamcity[testFinished name='TestA.testName']\n" + "\n" + "##teamcity[testSuiteFinished name='TestA']\n" + "\n" + "##teamcity[testSuiteStarted name='TestB' locationHint='java:suite://a.TestB']\n" + "\n" + "##teamcity[testStarted name='TestB.testName' locationHint='java:test://a.TestB.testName']\n" + "\n" + "##teamcity[testFinished name='TestB.testName']\n" + "\n" + "##teamcity[testSuiteFinished name='TestB']\n", StringUtil.convertLineSeparators(buf.toString()));
}
Also used : Description(org.junit.runner.Description) ArrayList(java.util.ArrayList) JUnit4TestListener(com.intellij.junit4.JUnit4TestListener) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 4 with JUnit4TestListener

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

the class JUnitTreeByDescriptionHierarchyTest method testClassWithMethodsWithoutSendTreeBefore.

@Test
public void testClassWithMethodsWithoutSendTreeBefore() throws Exception {
    Description root = Description.createSuiteDescription("ATest");
    List<Description> tests = new ArrayList<>();
    tests.add(Description.createTestDescription("ATest", "test1"));
    tests.add(Description.createTestDescription("ATest", "test2"));
    for (Description test : tests) {
        root.addChild(test);
    }
    final StringBuffer buf = new StringBuffer();
    JUnit4TestListener sender = createListener(buf);
    sender.testRunStarted(root);
    for (Description test : tests) {
        sender.testStarted(test);
        sender.testFinished(test);
    }
    sender.testRunFinished(new Result());
    Assert.assertEquals("output: " + buf, "##teamcity[enteredTheMatrix]\n" + "\n" + "##teamcity[testSuiteStarted name='ATest' locationHint='java:suite://ATest']\n" + "\n" + "##teamcity[testStarted name='ATest.test1' locationHint='java:test://ATest.test1']\n" + "\n" + "##teamcity[testFinished name='ATest.test1']\n" + "\n" + "##teamcity[testStarted name='ATest.test2' locationHint='java:test://ATest.test2']\n" + "\n" + "##teamcity[testFinished name='ATest.test2']\n" + "\n" + "##teamcity[testSuiteFinished name='ATest']\n", StringUtil.convertLineSeparators(buf.toString()));
}
Also used : Description(org.junit.runner.Description) ArrayList(java.util.ArrayList) JUnit4TestListener(com.intellij.junit4.JUnit4TestListener) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 5 with JUnit4TestListener

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

the class JUnitTreeByDescriptionHierarchyTest method testTearDownClassFailure.

@Test
public void testTearDownClassFailure() 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.testStarted(testName);
    sender.testFinished(testName);
    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[testSuiteStarted name='TestA']\n" + "\n" + "##teamcity[testStarted name='TestA.testName' locationHint='java:test://TestA.testName']\n" + "\n" + "##teamcity[testFinished name='TestA.testName']\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[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