Search in sources :

Example 31 with TestIdentifier

use of org.junit.platform.launcher.TestIdentifier in project intellij-community by JetBrains.

the class JUnit5EventsTest method multipleFailures.

@Test
void multipleFailures() throws Exception {
    TestDescriptor testDescriptor = new MethodTestDescriptor(UniqueId.forEngine("engine"), TestClass.class, TestClass.class.getDeclaredMethod("test1"));
    TestIdentifier identifier = TestIdentifier.from(testDescriptor);
    myExecutionListener.executionStarted(identifier);
    MultipleFailuresError multipleFailuresError = new MultipleFailuresError("2 errors");
    multipleFailuresError.addFailure(new AssertionFailedError("message1", "expected1", "actual1"));
    multipleFailuresError.addFailure(new AssertionFailedError("message2", "expected2", "actual2"));
    myExecutionListener.executionFinished(identifier, TestExecutionResult.failed(multipleFailuresError));
    Assertions.assertEquals("##teamcity[enteredTheMatrix]\n" + "\n" + "##teamcity[testStarted id='|[engine:engine|]' name='test1()' locationHint='java:test://com.intellij.junit5.JUnit5EventsTest$TestClass.test1']\n" + "\n" + "##teamcity[testFailed name='test1()' id='|[engine:engine|]' details='' message='' expected='expected1' actual='actual1']\n" + "\n" + "##teamcity[testFailed name='test1()' id='|[engine:engine|]' details='' message='' expected='expected2' actual='actual2']\n" + "\n" + "##teamcity[testFailed name='test1()' id='|[engine:engine|]' details='TRACE' message='2 errors (2 failures)|n\tmessage1|n\tmessage2']\n" + "\n" + "##teamcity[testFinished id='|[engine:engine|]' name='test1()']\n", StringUtil.convertLineSeparators(myBuf.toString()));
}
Also used : MethodTestDescriptor(org.junit.jupiter.engine.descriptor.MethodTestDescriptor) TestIdentifier(org.junit.platform.launcher.TestIdentifier) AssertionFailedError(org.opentest4j.AssertionFailedError) MethodTestDescriptor(org.junit.jupiter.engine.descriptor.MethodTestDescriptor) TestFactoryTestDescriptor(org.junit.jupiter.engine.descriptor.TestFactoryTestDescriptor) ClassTestDescriptor(org.junit.jupiter.engine.descriptor.ClassTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor) MultipleFailuresError(org.opentest4j.MultipleFailuresError)

Example 32 with TestIdentifier

use of org.junit.platform.launcher.TestIdentifier in project intellij-community by JetBrains.

the class JUnit5EventsTest method containerFailure.

@Test
void containerFailure() throws Exception {
    ClassTestDescriptor classTestDescriptor = new ClassTestDescriptor(UniqueId.forEngine("engine"), TestClass.class);
    TestDescriptor testDescriptor = new TestFactoryTestDescriptor(UniqueId.forEngine("engine1"), TestClass.class, TestClass.class.getDeclaredMethod("brokenStream"));
    TestIdentifier identifier = TestIdentifier.from(testDescriptor);
    final TestPlan testPlan = TestPlan.from(Collections.singleton(classTestDescriptor));
    myExecutionListener.sendTree(testPlan, "");
    myExecutionListener.executionStarted(identifier);
    myExecutionListener.executionFinished(identifier, TestExecutionResult.failed(new IllegalStateException()));
    Assertions.assertEquals("##teamcity[enteredTheMatrix]\n" + "##teamcity[treeEnded]\n" + "##teamcity[testSuiteStarted id='|[engine:engine1|]' name='brokenStream()']\n" + "\n" + "##teamcity[testStarted name='Class Configuration' locationHint='java:suite://com.intellij.junit5.JUnit5EventsTest$TestClass.brokenStream']\n" + "\n" + "##teamcity[testFailed name='Class Configuration' id='Class Configuration' details='TRACE' error='true' message='']\n" + "\n" + "##teamcity[testFinished name='Class Configuration']\n" + "##teamcity[testSuiteFinished  id='|[engine:engine1|]' name='brokenStream()']\n", StringUtil.convertLineSeparators(myBuf.toString()));
}
Also used : TestFactoryTestDescriptor(org.junit.jupiter.engine.descriptor.TestFactoryTestDescriptor) TestPlan(org.junit.platform.launcher.TestPlan) TestIdentifier(org.junit.platform.launcher.TestIdentifier) ClassTestDescriptor(org.junit.jupiter.engine.descriptor.ClassTestDescriptor) MethodTestDescriptor(org.junit.jupiter.engine.descriptor.MethodTestDescriptor) TestFactoryTestDescriptor(org.junit.jupiter.engine.descriptor.TestFactoryTestDescriptor) ClassTestDescriptor(org.junit.jupiter.engine.descriptor.ClassTestDescriptor) TestDescriptor(org.junit.platform.engine.TestDescriptor)

Example 33 with TestIdentifier

use of org.junit.platform.launcher.TestIdentifier in project intellij-community by JetBrains.

the class JUnit5NavigationTest method methodNavigation.

@Test
void methodNavigation() throws Exception {
    UniqueId uniqueId = UniqueId.parse("[class:JUnit5NavigationTest]/[method:methodNavigation]");
    MethodTestDescriptor methodTestDescriptor = new MethodTestDescriptor(uniqueId, JUnit5NavigationTest.class, JUnit5NavigationTest.class.getDeclaredMethod("methodNavigation"));
    TestIdentifier testIdentifier = TestIdentifier.from(methodTestDescriptor);
    Assertions.assertEquals(JUnit5NavigationTest.class.getName(), JUnit5TestExecutionListener.getClassName(testIdentifier));
    Assertions.assertEquals("methodNavigation", JUnit5TestExecutionListener.getMethodName(testIdentifier));
//Assertions.assertEquals("methodNavigation", testIdentifier.getDisplayName()); todo methodNavigation()
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) MethodTestDescriptor(org.junit.jupiter.engine.descriptor.MethodTestDescriptor) TestIdentifier(org.junit.platform.launcher.TestIdentifier) Test(org.junit.jupiter.api.Test)

Example 34 with TestIdentifier

use of org.junit.platform.launcher.TestIdentifier in project intellij-community by JetBrains.

the class JUnit5NavigationTest method locationHintValue.

private String locationHintValue() {
    descriptor.use(myTestSource);
    TestIdentifier testIdentifier = TestIdentifier.from(descriptor);
    return JUnit5TestExecutionListener.getLocationHintValue(testIdentifier.getSource().orElseThrow(IllegalStateException::new), testIdentifier.isTest());
}
Also used : TestIdentifier(org.junit.platform.launcher.TestIdentifier)

Example 35 with TestIdentifier

use of org.junit.platform.launcher.TestIdentifier in project ant by apache.

the class LegacyPlainResultFormatter method testPlanExecutionFinished.

@Override
public void testPlanExecutionFinished(final TestPlan testPlan) {
    for (final Map.Entry<TestIdentifier, Stats> entry : this.testIds.entrySet()) {
        final TestIdentifier testIdentifier = entry.getKey();
        if (!isTestClass(testIdentifier).isPresent()) {
            // we are not interested in anything other than a test "class" in this section
            continue;
        }
        final Stats stats = entry.getValue();
        final StringBuilder sb = new StringBuilder("Tests run: ").append(stats.numTestsRun.get());
        sb.append(", Failures: ").append(stats.numTestsFailed.get());
        sb.append(", Skipped: ").append(stats.numTestsSkipped.get());
        sb.append(", Aborted: ").append(stats.numTestsAborted.get());
        final long timeElapsed = stats.endedAt - stats.startedAt;
        sb.append(", Time elapsed: ");
        if (timeElapsed < 1000) {
            sb.append(timeElapsed).append(" milli sec(s)");
        } else {
            sb.append(TimeUnit.SECONDS.convert(timeElapsed, TimeUnit.MILLISECONDS)).append(" sec(s)");
        }
        try {
            this.writer.write(sb.toString());
            this.writer.newLine();
        } catch (IOException ioe) {
            handleException(ioe);
            return;
        }
    }
    // write out sysout and syserr content if any
    try {
        if (this.hasSysOut()) {
            this.writer.write("------------- Standard Output ---------------");
            this.writer.newLine();
            writeSysOut(writer);
            this.writer.write("------------- ---------------- ---------------");
            this.writer.newLine();
        }
        if (this.hasSysErr()) {
            this.writer.write("------------- Standard Error ---------------");
            this.writer.newLine();
            writeSysErr(writer);
            this.writer.write("------------- ---------------- ---------------");
            this.writer.newLine();
        }
    } catch (IOException ioe) {
        handleException(ioe);
        return;
    }
}
Also used : TestIdentifier(org.junit.platform.launcher.TestIdentifier) IOException(java.io.IOException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map)

Aggregations

TestIdentifier (org.junit.platform.launcher.TestIdentifier)53 Test (org.junit.jupiter.api.Test)29 TestPlan (org.junit.platform.launcher.TestPlan)23 TestExecutionResult (org.junit.platform.engine.TestExecutionResult)17 LauncherDiscoveryRequestBuilder (org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder)11 Categories (org.junit.vintage.engine.samples.junit4.Categories)10 TestExecutionListener (org.junit.platform.launcher.TestExecutionListener)8 ReportEntry (org.apache.maven.surefire.report.ReportEntry)7 SimpleReportEntry (org.apache.maven.surefire.report.SimpleReportEntry)7 EngineDescriptor (org.junit.platform.engine.support.descriptor.EngineDescriptor)7 LinkedHashMap (java.util.LinkedHashMap)6 EnclosedJUnit4TestCase (org.junit.vintage.engine.samples.junit4.EnclosedJUnit4TestCase)6 PlainJUnit4TestCaseWithFiveTestMethods (org.junit.vintage.engine.samples.junit4.PlainJUnit4TestCaseWithFiveTestMethods)6 Map (java.util.Map)5 TestDescriptor (org.junit.platform.engine.TestDescriptor)5 LauncherDiscoveryRequest (org.junit.platform.launcher.LauncherDiscoveryRequest)5 NumberFormat (java.text.NumberFormat)3 ArrayList (java.util.ArrayList)3 MethodTestDescriptor (org.junit.jupiter.engine.descriptor.MethodTestDescriptor)3 Launcher (org.junit.platform.launcher.Launcher)3