From 8fb27da0b4371e73ee1729d9751bf71f1751b11e Mon Sep 17 00:00:00 2001 From: Richard Richter Date: Tue, 17 Mar 2020 11:51:15 +0100 Subject: [PATCH] MidpointTestMixin: displayTestFooter now shows thrown exception This may duplicate report, but sometimes the exception is lost in logs. This should ensure that it appears in both logs and stdout. --- .../midpoint/tools/testng/MidpointTestMixin.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/test-ng/src/main/java/com/evolveum/midpoint/tools/testng/MidpointTestMixin.java b/tools/test-ng/src/main/java/com/evolveum/midpoint/tools/testng/MidpointTestMixin.java index 1730cac578a..23870f33f97 100644 --- a/tools/test-ng/src/main/java/com/evolveum/midpoint/tools/testng/MidpointTestMixin.java +++ b/tools/test-ng/src/main/java/com/evolveum/midpoint/tools/testng/MidpointTestMixin.java @@ -33,7 +33,7 @@ public interface MidpointTestMixin { String TEST_LOG_SECTION_SUFFIX = " --------------------------------------"; String DISPLAY_OUT_PREFIX = "\n*** "; - String DISPLAY_LOG_FORMAT1 = "*** {}"; + String DISPLAY_LOG_FORMAT1 = "*** {}:"; String DISPLAY_LOG_FORMAT2 = "*** {}:\n{}"; /** @@ -129,6 +129,10 @@ default void displayTestTitle(String testTitle) { * Not intended for tests classes, used by lifecycle methods in our test superclasses. */ default void displayTestFooter(String testTitle, ITestResult testResult) { + if (testResult.getThrowable() != null) { + displayException(testTitle + " thrown unexpected exception", testResult.getThrowable()); + } + long testMsDuration = testResult.getEndMillis() - testResult.getStartMillis(); System.out.println(TEST_OUT_FOOTER_PREFIX + testTitle + " FINISHED in " + testMsDuration + " ms" + TEST_OUT_FOOTER_SUFFIX); logger().info(TEST_LOG_PREFIX + testTitle + " FINISHED in " + testMsDuration + " ms" + TEST_LOG_SUFFIX); @@ -140,7 +144,7 @@ default void display(String text) { } /** - * Displays + * Displays value prefixed with provided title. */ default void displayValue(String title, Object value) { System.out.println(DISPLAY_OUT_PREFIX + title + "\n" + value); @@ -152,8 +156,8 @@ default void displayValue(String title, Object value) { * Use for "bad" exceptions, for expected exceptions use {@link #displayExpectedException}. */ default void displayException(String title, Throwable e) { - System.out.println(DISPLAY_OUT_PREFIX + title); - e.printStackTrace(); + System.out.println(DISPLAY_OUT_PREFIX + title + ":"); + e.printStackTrace(System.out); logger().debug(DISPLAY_LOG_FORMAT1, title, e); }