https://github.com/cuioss/cui-test-juli-logger
Provides some classes simplifying the configuration and asserting of logging in the context of unit-tests
https://github.com/cuioss/cui-test-juli-logger
java junit-jupiter logging
Last synced: 8 months ago
JSON representation
Provides some classes simplifying the configuration and asserting of logging in the context of unit-tests
- Host: GitHub
- URL: https://github.com/cuioss/cui-test-juli-logger
- Owner: cuioss
- License: apache-2.0
- Created: 2023-01-03T15:39:35.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-05-09T14:57:42.000Z (about 1 year ago)
- Last Synced: 2025-05-09T15:49:45.770Z (about 1 year ago)
- Topics: java, junit-jupiter, logging
- Language: Java
- Homepage:
- Size: 138 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.adoc
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
= cui-test-juli-logger
== Status
image:https://github.com/cuioss/cui-test-juli-logger/actions/workflows/maven.yml/badge.svg[Java CI with Maven,link=https://github.com/cuioss/cui-test-juli-logger/actions/workflows/maven.yml]
image:http://img.shields.io/:license-apache-blue.svg[License,link=http://www.apache.org/licenses/LICENSE-2.0.html]
image:https://img.shields.io/maven-central/v/de.cuioss.test/cui-test-juli-logger.svg[Maven Central,link=https://central.sonatype.com/artifact/de.cuioss.test/cui-test-juli-logger]
https://sonarcloud.io/summary/new_code?id=cuioss_cui-test-juli-logger[image:https://sonarcloud.io/api/project_badges/measure?project=cuioss_cui-test-juli-logger&metric=alert_status[Quality
Gate Status]]
image:https://sonarcloud.io/api/project_badges/measure?project=cuioss_cui-test-juli-logger&metric=ncloc[Lines of Code,link=https://sonarcloud.io/summary/new_code?id=cuioss_cui-test-juli-logger]
image:https://sonarcloud.io/api/project_badges/measure?project=cuioss_cui-test-juli-logger&metric=coverage[Coverage,link=https://sonarcloud.io/summary/new_code?id=cuioss_cui-test-juli-logger]
https://cuioss.github.io/cui-test-juli-logger/about.html[Generated Documentation on github-pages]
== What is it?
Provides some classes simplifying the configuration and asserting of logging in the context of unit-tests.
=== Maven Coordinates
[source,xml]
----
de.cuioss.test
cui-test-juli-logger
----
== How To use it
Enable for a unit-test
[source,java]
----
@EnableTestLogger
class PortalHealthServletTest {}
----
Configure for all tests
[source,java]
----
@EnableTestLogger(rootLevel = TestLogLevel.INFO, trace = List.class, error = Set.class)
class PortalHealthServletTest {}
----
The logger and level are resetted for each test
Asserting log statements: written or not:
[source,java]
----
@EnableTestLogger
class PortalHealthServletTest {
@Test
void shouldAssertLogs() {
LogAsserts.assertLogMessagePresent(TestLogLevel.DEBUG, "Should be there at least once");
LogAsserts.assertSingleLogMessagePresent(TestLogLevel.INFO, "Should be there exactly once");
LogAsserts.assertLogMessagePresentContaining(TestLogLevel.INFO, "part of the expected message");
LogAsserts.assertNoLogMessagePresent(TestLogLevel.WARN, PortalHealthServlet.class);
// and many more asserts
}
----
Changing LogLevel dynamically:
[source,java]
----
TestLogLevel.DEBUG.addLogger(PortalHealthServlet.class);
// Set Root-level to debug
TestLogLevel.DEBUG.setAsRootLevel();
----
Advanced Usage:
[source,java]
----
// Programmatic Setup and teardown, usually done by EnableTestLogger / TestLoggerController
TestLoggerFactory.install();
TestLoggerFactory.uninstall();
// Access the TestLogHandler (for advanced queries not covered by LogAsserts)
TestLoggerFactory.getTestHandler();
----