From e5f8ed046aedf62ee725052aec2d5e3e943c07f6 Mon Sep 17 00:00:00 2001 From: David Kornel Date: Tue, 19 Nov 2024 11:29:48 +0100 Subject: [PATCH] Log state of test execution result using visual separator (#199) ## Description Visual test separator logged only that test FINISHED, not it will log status of test so SUCCESS or FAILED ## Type of Change Please delete options that are not relevant. * New feature (non-breaking change which adds functionality) ## Checklist - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] My changes generate no new warnings - [x] New and existing unit/integration tests pass locally with my changes Signed-off-by: David Kornel --- .../listeners/TestVisualSeparatorExtension.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/test-frame-common/src/main/java/io/skodjob/testframe/listeners/TestVisualSeparatorExtension.java b/test-frame-common/src/main/java/io/skodjob/testframe/listeners/TestVisualSeparatorExtension.java index 4d699e9..01ac763 100644 --- a/test-frame-common/src/main/java/io/skodjob/testframe/listeners/TestVisualSeparatorExtension.java +++ b/test-frame-common/src/main/java/io/skodjob/testframe/listeners/TestVisualSeparatorExtension.java @@ -18,7 +18,7 @@ */ public class TestVisualSeparatorExtension implements BeforeEachCallback, AfterEachCallback, BeforeAllCallback, AfterAllCallback { - private final Logger logger = LoggerFactory.getLogger(TestVisualSeparatorExtension.class); + private static final Logger LOGGER = LoggerFactory.getLogger(TestVisualSeparatorExtension.class); private TestVisualSeparatorExtension() { // Private constructor to prevent instantiation @@ -27,26 +27,31 @@ private TestVisualSeparatorExtension() { @Override public void beforeAll(ExtensionContext extensionContext) { LoggerUtils.logSeparator(); - logger.info("TestClass {} STARTED", extensionContext.getRequiredTestClass().getName()); + LOGGER.info("TestClass {} STARTED", extensionContext.getRequiredTestClass().getName()); } @Override public void afterAll(ExtensionContext extensionContext) { - logger.info("TestClass {} FINISHED", extensionContext.getRequiredTestClass().getName()); + LOGGER.info("TestClass {} FINISHED", extensionContext.getRequiredTestClass().getName()); LoggerUtils.logSeparator(); } @Override public void beforeEach(ExtensionContext extensionContext) { LoggerUtils.logSeparator(); - logger.info("Test {}.{} STARTED", extensionContext.getRequiredTestClass().getName(), + LOGGER.info("Test {}.{} STARTED", extensionContext.getRequiredTestClass().getName(), extensionContext.getDisplayName().replace("()", "")); } @Override public void afterEach(ExtensionContext extensionContext) { - logger.info("Test {}.{} FINISHED", extensionContext.getRequiredTestClass().getName(), - extensionContext.getDisplayName().replace("()", "")); + String state = "SUCCEEDED"; + if (extensionContext.getExecutionException().isPresent()) { + state = "FAILED"; + } + + LOGGER.info("Test {}.{} {}", extensionContext.getRequiredTestClass().getName(), + extensionContext.getDisplayName().replace("()", ""), state); LoggerUtils.logSeparator(); } }