Search in sources :

Example 11 with TestDescriptorStub

use of org.junit.platform.fakes.TestDescriptorStub in project junit5 by junit-team.

the class DefaultLauncherTests method testPlanThrowsExceptionWhenModified.

@Test
@SuppressWarnings("deprecation")
void testPlanThrowsExceptionWhenModified() {
    TestEngine engine = new TestEngineSpy();
    var launcher = createLauncher(engine);
    var testPlan = launcher.discover(request().build());
    var engineIdentifier = getOnlyElement(testPlan.getRoots());
    var engineUniqueId = UniqueId.parse(engineIdentifier.getUniqueId());
    assertThat(testPlan.getChildren(engineIdentifier)).hasSize(1);
    var addedIdentifier = TestIdentifier.from(new TestDescriptorStub(engineUniqueId.append("test", "test2"), "test2"));
    var exception = assertThrows(JUnitException.class, () -> testPlan.add(addedIdentifier));
    assertThat(exception).hasMessage("Unsupported attempt to modify the TestPlan was detected. " + "Please contact your IDE/tool vendor and request a fix or downgrade to JUnit 5.7.x (see https://github.com/junit-team/junit5/issues/1732 for details).");
    assertThat(testPlan.getChildren(engineIdentifier)).hasSize(1).doesNotContain(addedIdentifier);
}
Also used : DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) TestEngine(org.junit.platform.engine.TestEngine) TestDescriptorStub(org.junit.platform.fakes.TestDescriptorStub) TestEngineSpy(org.junit.platform.fakes.TestEngineSpy) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with TestDescriptorStub

use of org.junit.platform.fakes.TestDescriptorStub in project junit5 by junit-team.

the class XmlReportWriterTests method writesValidXmlEvenIfExceptionMessageContainsCData.

@Test
void writesValidXmlEvenIfExceptionMessageContainsCData() throws Exception {
    var uniqueId = engineDescriptor.getUniqueId().append("test", "test");
    engineDescriptor.addChild(new TestDescriptorStub(uniqueId, "test"));
    var testPlan = TestPlan.from(Set.of(engineDescriptor), configParams);
    var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
    var assertionError = new AssertionError("<foo><![CDATA[bar]]></foo>");
    reportData.markFinished(testPlan.getTestIdentifier(uniqueId.toString()), failed(assertionError));
    var testsuite = writeXmlReport(testPlan, reportData);
    assertValidAccordingToJenkinsSchema(testsuite.document());
    assertThat(testsuite.find("failure").attr("message")).isEqualTo("<foo><![CDATA[bar]]></foo>");
}
Also used : TestDescriptorStub(org.junit.platform.fakes.TestDescriptorStub) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with TestDescriptorStub

use of org.junit.platform.fakes.TestDescriptorStub in project junit5 by junit-team.

the class XmlReportWriterTests method writesEmptySkippedElementForSkippedTestWithoutReason.

@Test
void writesEmptySkippedElementForSkippedTestWithoutReason() throws Exception {
    var uniqueId = engineDescriptor.getUniqueId().append("test", "test");
    engineDescriptor.addChild(new TestDescriptorStub(uniqueId, "skippedTest"));
    var testPlan = TestPlan.from(Set.of(engineDescriptor), configParams);
    var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
    reportData.markSkipped(testPlan.getTestIdentifier(uniqueId.toString()), null);
    var testsuite = writeXmlReport(testPlan, reportData);
    assertValidAccordingToJenkinsSchema(testsuite.document());
    var testcase = testsuite.child("testcase");
    assertThat(testcase.attr("name")).isEqualTo("skippedTest");
    var skipped = testcase.child("skipped");
    assertThat(skipped.size()).isEqualTo(1);
    assertThat(skipped.children()).isEmpty();
}
Also used : TestDescriptorStub(org.junit.platform.fakes.TestDescriptorStub) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with TestDescriptorStub

use of org.junit.platform.fakes.TestDescriptorStub in project junit5 by junit-team.

the class XmlReportWriterTests method escapesInvalidCharactersInSystemPropertiesAndExceptionMessages.

@Test
void escapesInvalidCharactersInSystemPropertiesAndExceptionMessages() throws Exception {
    var uniqueId = engineDescriptor.getUniqueId().append("test", "test");
    engineDescriptor.addChild(new TestDescriptorStub(uniqueId, "test"));
    var testPlan = TestPlan.from(Set.of(engineDescriptor), configParams);
    var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
    var assertionError = new AssertionError("expected: <A> but was: <B\0>");
    reportData.markFinished(testPlan.getTestIdentifier(uniqueId.toString()), failed(assertionError));
    System.setProperty("foo.bar", "\1");
    Match testsuite;
    try {
        testsuite = writeXmlReport(testPlan, reportData);
    } finally {
        System.getProperties().remove("foo.bar");
    }
    assertValidAccordingToJenkinsSchema(testsuite.document());
    // 
    assertThat(testsuite.find("property").matchAttr("name", "foo\\.bar").attr("value")).isEqualTo("&#1;");
    var failure = testsuite.find("failure");
    // 
    assertThat(failure.attr("message")).isEqualTo("expected: <A> but was: <B&#0;>");
    // 
    assertThat(failure.text()).contains("AssertionError: expected: <A> but was: <B&#0;>");
}
Also used : TestDescriptorStub(org.junit.platform.fakes.TestDescriptorStub) Match(org.joox.Match) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with TestDescriptorStub

use of org.junit.platform.fakes.TestDescriptorStub in project junit5 by junit-team.

the class XmlReportWriterTests method doesNotReopenCDataWithinCDataContent.

@Test
void doesNotReopenCDataWithinCDataContent() throws Exception {
    var uniqueId = engineDescriptor.getUniqueId().append("test", "test");
    engineDescriptor.addChild(new TestDescriptorStub(uniqueId, "test"));
    var testPlan = TestPlan.from(Set.of(engineDescriptor), configParams);
    var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone());
    var assertionError = new AssertionError("<foo><![CDATA[bar]]></foo>");
    reportData.markFinished(testPlan.getTestIdentifier(uniqueId.toString()), failed(assertionError));
    Writer assertingWriter = new StringWriter() {

        @SuppressWarnings("NullableProblems")
        @Override
        public void write(char[] buffer, int off, int len) {
            assertThat(new String(buffer, off, len)).doesNotContain("]]><![CDATA[");
        }
    };
    writeXmlReport(testPlan, reportData, assertingWriter);
}
Also used : StringWriter(java.io.StringWriter) TestDescriptorStub(org.junit.platform.fakes.TestDescriptorStub) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TestDescriptorStub (org.junit.platform.fakes.TestDescriptorStub)22 Test (org.junit.jupiter.api.Test)19 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 EngineDescriptor (org.junit.platform.engine.support.descriptor.EngineDescriptor)6 TestDescriptor (org.junit.platform.engine.TestDescriptor)5 TestEngineSpy (org.junit.platform.fakes.TestEngineSpy)3 StringWriter (java.io.StringWriter)2 RepeatedTest (org.junit.jupiter.api.RepeatedTest)2 EngineDiscoveryRequest (org.junit.platform.engine.EngineDiscoveryRequest)2 ExecutionRequest (org.junit.platform.engine.ExecutionRequest)2 TestEngine (org.junit.platform.engine.TestEngine)2 UniqueId (org.junit.platform.engine.UniqueId)2 DiscoverySelectors.selectUniqueId (org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId)2 AbstractTestDescriptor (org.junit.platform.engine.support.descriptor.AbstractTestDescriptor)2 DemoHierarchicalTestEngine (org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine)2 PrintWriter (java.io.PrintWriter)1 Writer (java.io.Writer)1 LinkedHashMap (java.util.LinkedHashMap)1 Optional (java.util.Optional)1 Level (java.util.logging.Level)1