Search in sources :

Example 1 with AssertionFailedError

use of org.opentest4j.AssertionFailedError in project spring-framework by spring-projects.

the class FailingBeforeAndAfterMethodsSpringExtensionTestCase method runTestAndAssertCounters.

private void runTestAndAssertCounters(Class<?> testClass) {
    Launcher launcher = LauncherFactory.create();
    ExceptionTrackingListener listener = new ExceptionTrackingListener();
    launcher.registerTestExecutionListeners(listener);
    launcher.execute(request().selectors(selectClass(testClass)).build());
    TestExecutionSummary summary = listener.getSummary();
    String name = testClass.getSimpleName();
    int expectedStartedCount = getExpectedStartedCount(testClass);
    int expectedSucceededCount = getExpectedSucceededCount(testClass);
    int expectedFailedCount = getExpectedFailedCount(testClass);
    // @formatter:off
    assertAll(() -> assertEquals(1, summary.getTestsFoundCount(), () -> name + ": tests found"), () -> assertEquals(0, summary.getTestsSkippedCount(), () -> name + ": tests skipped"), () -> assertEquals(0, summary.getTestsAbortedCount(), () -> name + ": tests aborted"), () -> assertEquals(expectedStartedCount, summary.getTestsStartedCount(), () -> name + ": tests started"), () -> assertEquals(expectedSucceededCount, summary.getTestsSucceededCount(), () -> name + ": tests succeeded"), () -> assertEquals(expectedFailedCount, summary.getTestsFailedCount(), () -> name + ": tests failed"));
    // something else like an error in the @Configuration class, etc.
    if (expectedFailedCount > 0) {
        assertEquals(1, listener.exceptions.size(), "exceptions expected");
        Throwable exception = listener.exceptions.get(0);
        if (!(exception instanceof AssertionFailedError)) {
            throw new AssertionFailedError(exception.getClass().getName() + " is not an instance of " + AssertionFailedError.class.getName(), exception);
        }
    }
}
Also used : TestExecutionSummary(org.junit.platform.launcher.listeners.TestExecutionSummary) Launcher(org.junit.platform.launcher.Launcher) AssertionFailedError(org.opentest4j.AssertionFailedError)

Example 2 with AssertionFailedError

use of org.opentest4j.AssertionFailedError in project junit5 by junit-team.

the class XmlReportsWritingListenerTests method writesFileForSingleFailingTest.

@Test
void writesFileForSingleFailingTest(@Root Path tempDirectory) throws Exception {
    DemoHierarchicalTestEngine engine = new DemoHierarchicalTestEngine("dummy");
    engine.addTest("failingTest", () -> fail("expected to <b>fail</b>"));
    executeTests(engine, tempDirectory);
    String content = readValidXmlFile(tempDirectory.resolve("TEST-dummy.xml"));
    // @formatter:off
    assertThat(content).containsSubsequence("<testsuite name=\"dummy\" tests=\"1\" skipped=\"0\" failures=\"1\" errors=\"0\"", "<testcase name=\"failingTest\"", "<failure message=\"expected to &lt;b&gt;fail&lt;/b&gt;\" type=\"" + AssertionFailedError.class.getName() + "\">", "AssertionFailedError: expected to <b>fail</b>", "\tat", "</failure>", "</testcase>", "</testsuite>").doesNotContain("<skipped").doesNotContain("<error");
// @formatter:on
}
Also used : DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) AssertionFailedError(org.opentest4j.AssertionFailedError) Test(org.junit.jupiter.api.Test)

Example 3 with AssertionFailedError

use of org.opentest4j.AssertionFailedError in project junit5 by junit-team.

the class XmlReportsWritingListenerTests method writesFileForFailingContainer.

@Test
void writesFileForFailingContainer(@Root Path tempDirectory) throws Exception {
    DemoHierarchicalTestEngine engine = new DemoHierarchicalTestEngine("dummy");
    engine.addTest("test", () -> fail("never called"));
    engine.getEngineDescriptor().setBeforeAllBehavior(() -> fail("failure before all tests"));
    executeTests(engine, tempDirectory);
    String content = readValidXmlFile(tempDirectory.resolve("TEST-dummy.xml"));
    // @formatter:off
    assertThat(content).containsSubsequence("<testsuite name=\"dummy\" tests=\"1\" skipped=\"0\" failures=\"1\" errors=\"0\"", "<testcase name=\"test\"", "<failure message=\"failure before all tests\" type=\"" + AssertionFailedError.class.getName() + "\">", "AssertionFailedError: failure before all tests", "\tat", "</failure>", "</testcase>", "</testsuite>");
// @formatter:on
}
Also used : DemoHierarchicalTestEngine(org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine) AssertionFailedError(org.opentest4j.AssertionFailedError) Test(org.junit.jupiter.api.Test)

Example 4 with AssertionFailedError

use of org.opentest4j.AssertionFailedError in project junit5 by junit-team.

the class AssertTimeoutAssertionsTests method assertTimeoutPreemptivelyWithMessageSupplierForSupplierThatCompletesAfterTheTimeout.

@Test
void assertTimeoutPreemptivelyWithMessageSupplierForSupplierThatCompletesAfterTheTimeout() {
    AssertionFailedError error = assertThrows(AssertionFailedError.class, () -> {
        assertTimeoutPreemptively(ofMillis(50), () -> {
            Thread.sleep(100);
            return "Tempus Fugit";
        }, () -> "Tempus" + " " + "Fugit");
        fail("timeout exception should be thrown");
    });
    assertMessageEquals(error, "Tempus Fugit ==> execution timed out after 50 ms");
}
Also used : AssertionFailedError(org.opentest4j.AssertionFailedError)

Example 5 with AssertionFailedError

use of org.opentest4j.AssertionFailedError in project junit5 by junit-team.

the class AssertTimeoutAssertionsTests method assertTimeoutForSupplierThatCompletesAfterTheTimeout.

@Test
void assertTimeoutForSupplierThatCompletesAfterTheTimeout() {
    AssertionFailedError error = assertThrows(AssertionFailedError.class, () -> {
        assertTimeout(ofMillis(50), () -> {
            Thread.sleep(100);
            return "Tempus Fugit";
        });
        fail("timeout assertion should be thrown");
    });
    assertMessageStartsWith(error, "execution exceeded timeout of 50 ms by");
}
Also used : AssertionFailedError(org.opentest4j.AssertionFailedError)

Aggregations

AssertionFailedError (org.opentest4j.AssertionFailedError)42 Test (org.junit.jupiter.api.Test)9 AssertionTestUtils.expectAssertionFailedError (org.junit.jupiter.api.AssertionTestUtils.expectAssertionFailedError)8 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)4 URI (java.net.URI)4 Executable (org.junit.jupiter.api.function.Executable)4 WithMockUser (org.springframework.security.test.context.support.WithMockUser)4 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)4 SettingsProxyModel (com.synopsys.integration.alert.common.rest.model.SettingsProxyModel)2 DemoHierarchicalTestEngine (org.junit.platform.engine.support.hierarchical.DemoHierarchicalTestEngine)2 MultipleFailuresError (org.opentest4j.MultipleFailuresError)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ComparisonFailureData (com.intellij.rt.execution.junit.ComparisonFailureData)1 InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)1 Result (io.cucumber.plugin.event.Result)1 TestCaseFinished (io.cucumber.plugin.event.TestCaseFinished)1 TestCaseStarted (io.cucumber.plugin.event.TestCaseStarted)1 TestStepFinished (io.cucumber.plugin.event.TestStepFinished)1 TestStepStarted (io.cucumber.plugin.event.TestStepStarted)1 IOException (java.io.IOException)1