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);
}
}
}
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 <b>fail</b>\" type=\"" + AssertionFailedError.class.getName() + "\">", "AssertionFailedError: expected to <b>fail</b>", "\tat", "</failure>", "</testcase>", "</testsuite>").doesNotContain("<skipped").doesNotContain("<error");
// @formatter:on
}
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
}
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");
}
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");
}
Aggregations