Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sterlp/log4j-test-logger
Simple in memory log4j2 appender to assert log messages in JUnit tests
https://github.com/sterlp/log4j-test-logger
appender assert junit junit5 log log4j2 logging logs message test testing
Last synced: 13 days ago
JSON representation
Simple in memory log4j2 appender to assert log messages in JUnit tests
- Host: GitHub
- URL: https://github.com/sterlp/log4j-test-logger
- Owner: sterlp
- License: mit
- Created: 2021-05-04T05:42:04.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-02-02T20:15:53.000Z (almost 3 years ago)
- Last Synced: 2024-04-16T07:09:17.365Z (7 months ago)
- Topics: appender, assert, junit, junit5, log, log4j2, logging, logs, message, test, testing
- Language: Java
- Homepage:
- Size: 23.4 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Java CI with Maven](https://github.com/sterlp/log4j-test-logger/actions/workflows/maven.yml/badge.svg)](https://github.com/sterlp/log4j-test-logger/actions/workflows/maven.yml)
# log4j-test-logger
Simple in memory log4j2 appender to assert logs in JUnit tests.# Alternative if you use Spring
https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/test/system/OutputCaptureExtension.html# Usage
```java
@BeforeEach
void before() {
TestAppender.clear();
}
@Test
void yourTestMethod() {
// GIVEN: log is clean
TestAppender.clear();// WHEN: I call my fancy method
subject.doFancyStuff(argument);// THEN: I should have
assertFalse(TestAppender.first(Level.INFO, "Fancy method executed").isPresent());
assertEquals(1, TestAppender.count(Level.INFO));
assertEquals(0, TestAppender.count(Level.WARN));
assertEquals(0, TestAppender.count(Level.ERROR));
}
```# Configuration
## Dependency Maven pom.xml```xml
org.sterl.test.log4j
log4j-test-logger
0.1.0
test
```## Configuration log4j2.xml
In your `src/test/resources` add or extend the log4j file:
```xml
```