Search in sources :

Example 1 with EngineDescriptor

use of org.junit.platform.engine.support.descriptor.EngineDescriptor in project junit5 by junit-team.

the class XmlReportWriterTests method writesEmptyErrorElementForFailedTestWithoutCause.

@Test
void writesEmptyErrorElementForFailedTestWithoutCause() throws Exception {
    engineDescriptor = new EngineDescriptor(UniqueId.forEngine("myEngineId"), "Fancy Engine") {

        @Override
        public String getLegacyReportingName() {
            return "myEngine";
        }
    };
    UniqueId uniqueId = engineDescriptor.getUniqueId().append("test", "test");
    engineDescriptor.addChild(new TestDescriptorStub(uniqueId, "some fancy name") {

        @Override
        public String getLegacyReportingName() {
            return "failedTest";
        }
    });
    TestPlan testPlan = TestPlan.from(singleton(engineDescriptor));
    XmlReportData reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
    reportData.markFinished(testPlan.getTestIdentifier(uniqueId.toString()), failed(null));
    String content = writeXmlReport(testPlan, reportData);
    assertValidAccordingToJenkinsSchema(content);
    // @formatter:off
    assertThat(content).containsSubsequence("<testcase name=\"failedTest\" classname=\"myEngine\"", "<error/>", "</testcase>");
// @formatter:on
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) TestPlan(org.junit.platform.launcher.TestPlan) EngineDescriptor(org.junit.platform.engine.support.descriptor.EngineDescriptor) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) Test(org.junit.jupiter.api.Test)

Example 2 with EngineDescriptor

use of org.junit.platform.engine.support.descriptor.EngineDescriptor in project junit5 by junit-team.

the class XmlReportsWritingListenerTests method writesReportEntriesToSystemOutElement.

@Test
void writesReportEntriesToSystemOutElement(@Root Path tempDirectory, TestReporter testReporter) throws Exception {
    EngineDescriptor engineDescriptor = new EngineDescriptor(UniqueId.forEngine("engine"), "Engine");
    engineDescriptor.addChild(new TestDescriptorStub(UniqueId.root("child", "test"), "test"));
    TestPlan testPlan = TestPlan.from(singleton(engineDescriptor));
    StringWriter out = new StringWriter();
    XmlReportsWritingListener listener = new XmlReportsWritingListener(tempDirectory, new PrintWriter(out));
    listener.testPlanExecutionStarted(testPlan);
    TestIdentifier testIdentifier = testPlan.getTestIdentifier("[child:test]");
    listener.executionStarted(testIdentifier);
    listener.reportingEntryPublished(testIdentifier, ReportEntry.from("foo", "bar"));
    Map<String, String> map = new LinkedHashMap<>();
    map.put("bar", "baz");
    map.put("qux", "foo");
    listener.reportingEntryPublished(testIdentifier, ReportEntry.from(map));
    listener.executionFinished(testIdentifier, successful());
    listener.executionFinished(testPlan.getTestIdentifier("[engine:engine]"), successful());
    String content = readValidXmlFile(tempDirectory.resolve("TEST-engine.xml"));
    // testReporter.publishEntry("xml", content);
    // @formatter:off
    assertThat(content).containsSubsequence("<testsuite", "<testcase", "<system-out>", "Report Entry #1 (timestamp: " + Year.now(), "- foo: bar\n", "Report Entry #2 (timestamp: " + Year.now(), "- bar: baz\n", "- qux: foo\n", "</system-out>", "</testcase>", "</testsuite>");
// @formatter:on
}
Also used : StringWriter(java.io.StringWriter) TestPlan(org.junit.platform.launcher.TestPlan) EngineDescriptor(org.junit.platform.engine.support.descriptor.EngineDescriptor) TestIdentifier(org.junit.platform.launcher.TestIdentifier) TestDescriptorStub(org.junit.platform.engine.test.TestDescriptorStub) PrintWriter(java.io.PrintWriter) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 3 with EngineDescriptor

use of org.junit.platform.engine.support.descriptor.EngineDescriptor in project junit5 by junit-team.

the class RunListenerAdapterTests method notifiedWithParentDisplayNameWhenTestClassUnknown.

@Test
void notifiedWithParentDisplayNameWhenTestClassUnknown() throws Exception {
    // Set up a test plan
    TestPlan plan = TestPlan.from(Collections.singletonList(new EngineDescriptor(newId(), "Luke's Plan")));
    adapter.testPlanExecutionStarted(plan);
    // Use the test plan to set up child with parent.
    final String parentDisplay = "I am your father";
    TestIdentifier child = newSourcelessChildIdentifierWithParent(plan, parentDisplay, null);
    adapter.executionStarted(child);
    // Check that the adapter has informed Surefire that the test has been invoked,
    // with the parent name as source (since the test case itself had no source).
    ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class);
    verify(listener).testStarting(entryCaptor.capture());
    assertEquals(parentDisplay, entryCaptor.getValue().getSourceName());
}
Also used : TestPlan(org.junit.platform.launcher.TestPlan) ReportEntry(org.apache.maven.surefire.report.ReportEntry) SimpleReportEntry(org.apache.maven.surefire.report.SimpleReportEntry) EngineDescriptor(org.junit.platform.engine.support.descriptor.EngineDescriptor) TestIdentifier(org.junit.platform.launcher.TestIdentifier) Test(org.junit.jupiter.api.Test)

Example 4 with EngineDescriptor

use of org.junit.platform.engine.support.descriptor.EngineDescriptor in project junit5 by junit-team.

the class RunListenerAdapterTests method notifiedWithCorrectNamesWhenClassExecutionFailed.

@Test
void notifiedWithCorrectNamesWhenClassExecutionFailed() throws Exception {
    ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class);
    TestPlan testPlan = TestPlan.from(Collections.singletonList(new EngineDescriptor(newId(), "Luke's Plan")));
    adapter.testPlanExecutionStarted(testPlan);
    adapter.executionFinished(identifiersAsParentOnTestPlan(testPlan, newEngineDescriptor(), newClassDescriptor()), TestExecutionResult.failed(new AssertionError()));
    verify(listener).testFailed(entryCaptor.capture());
    ReportEntry entry = entryCaptor.getValue();
    assertEquals(MyTestClass.class.getTypeName(), entry.getSourceName());
    assertNotNull(entry.getStackTraceWriter());
}
Also used : TestPlan(org.junit.platform.launcher.TestPlan) ReportEntry(org.apache.maven.surefire.report.ReportEntry) SimpleReportEntry(org.apache.maven.surefire.report.SimpleReportEntry) EngineDescriptor(org.junit.platform.engine.support.descriptor.EngineDescriptor) Test(org.junit.jupiter.api.Test)

Example 5 with EngineDescriptor

use of org.junit.platform.engine.support.descriptor.EngineDescriptor in project junit5 by junit-team.

the class RunListenerAdapterTests method notifiedForTestSetForSingleNodeEngine.

@Test
void notifiedForTestSetForSingleNodeEngine() {
    EngineDescriptor engine = new EngineDescriptor(UniqueId.forEngine("engine"), "engine") {

        @Override
        public Type getType() {
            return Type.TEST;
        }
    };
    TestPlan plan = TestPlan.from(Collections.singletonList(engine));
    adapter.testPlanExecutionStarted(plan);
    adapter.executionStarted(TestIdentifier.from(engine));
    InOrder inOrder = inOrder(listener);
    inOrder.verify(listener).testSetStarting(new SimpleReportEntry(JUnitPlatformProvider.class.getName(), "engine"));
    inOrder.verify(listener).testStarting(new SimpleReportEntry("<unrooted>", "engine"));
    inOrder.verifyNoMoreInteractions();
    adapter.executionFinished(TestIdentifier.from(engine), successful());
    inOrder = inOrder(listener);
    inOrder.verify(listener).testSucceeded(new SimpleReportEntry("<unrooted>", "engine"));
    inOrder.verify(listener).testSetCompleted(new SimpleReportEntry(JUnitPlatformProvider.class.getName(), "engine"));
    inOrder.verifyNoMoreInteractions();
}
Also used : SimpleReportEntry(org.apache.maven.surefire.report.SimpleReportEntry) InOrder(org.mockito.InOrder) TestPlan(org.junit.platform.launcher.TestPlan) EngineDescriptor(org.junit.platform.engine.support.descriptor.EngineDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

EngineDescriptor (org.junit.platform.engine.support.descriptor.EngineDescriptor)19 Test (org.junit.jupiter.api.Test)18 TestPlan (org.junit.platform.launcher.TestPlan)15 SimpleReportEntry (org.apache.maven.surefire.report.SimpleReportEntry)11 ReportEntry (org.apache.maven.surefire.report.ReportEntry)7 TestIdentifier (org.junit.platform.launcher.TestIdentifier)7 TestDescriptorStub (org.junit.platform.engine.test.TestDescriptorStub)5 ClassTestDescriptor (org.junit.jupiter.engine.descriptor.ClassTestDescriptor)3 TestMethodTestDescriptor (org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor)3 TestDescriptor (org.junit.platform.engine.TestDescriptor)3 TestExecutionResult (org.junit.platform.engine.TestExecutionResult)3 AbstractTestDescriptor (org.junit.platform.engine.support.descriptor.AbstractTestDescriptor)3 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 InOrder (org.mockito.InOrder)2 Path (java.nio.file.Path)1 LinkedHashMap (java.util.LinkedHashMap)1 JupiterEngineDescriptor (org.junit.jupiter.engine.descriptor.JupiterEngineDescriptor)1 DiscoverySelectorResolver (org.junit.jupiter.engine.discovery.DiscoverySelectorResolver)1 UniqueId (org.junit.platform.engine.UniqueId)1