Skip to content

Commit

Permalink
Log state of test execution result using visual separator (#199)
Browse files Browse the repository at this point in the history
## 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 <[email protected]>
  • Loading branch information
kornys authored Nov 19, 2024
1 parent 2e6190f commit e5f8ed0
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
}

0 comments on commit e5f8ed0

Please sign in to comment.