netmikey / logunit Goto Github PK
View Code? Open in Web Editor NEWA Java library for unit-testing logging.
License: Apache License 2.0
A Java library for unit-testing logging.
License: Apache License 2.0
Recently release logunit-logback:1.1.1
publishes Gradle module file which declares that this module requires java 11:
"attributes": {
"org.gradle.category": "library",
"org.gradle.dependency.bundling": "external",
"org.gradle.jvm.version": 11,
"org.gradle.libraryelements": "jar",
"org.gradle.usage": "java-api"
},
This contradicts README claim that java 8 is supported. Probably the easiest way to fix this is to configure java compiler in your build scripts with release=8
option: https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation
That would be cool to have the map of diagnostic context in the final log event. This is equivalent to ThreadContext Map in log4j2, and to MDC in logback.
That would allow to test that ThreadContext.put()
and MDC.put
is being called.
Hi,
First, I would like to thank you for this project. It is nicely implemented and very useful.
I would like to report an issue when running the tests in parallel with the following properties:
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
Attaching a small project to reproduce - parallel-tests.zip
If I uncomment the @Execution(ExecutionMode.SAME_THREAD)
on the ParallelTest
class or use @ResourceLock("LogCapturer")
on both test methods, everything works.
Run the tests by executing:
mvn clean test
BTW - I used Flogger which uses slf4j to log4j2
Thanks!
I want to test Log4J2 messages and use logunit-core together with logunit-log4j2 (v2.0.0). Here is my test class:
import io.github.netmikey.logunit.api.LogCapturer;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.Assertions.*;
@TestMethodOrder(MethodOrderer.MethodName.class)
class LogTest {
@RegisterExtension
LogCapturer logCapturer = LogCapturer.create().captureForType(LogTest.class);
private static final Logger log = LoggerFactory.getLogger(LogTest.class);
@BeforeEach
void createLog() {
log.info("Test-Log created.");
}
@Test
void getEvents() {
//log.info("Get events.");
assertFalse(logCapturer.getEvents().isEmpty());
}
@Test
void testMessage() {
//log.info("Test message.");
logCapturer.assertContains("Test");
}
}
I see the log ("Test-Log created.") but the tests fail. This is the same problem I have with real tests. Only in some cases the events are not empty.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.