Different logging services can be tested using mock loggers backed by Mockito.
Warning
This library does not support parallel test execution.
The simplest usage example looks like this:
@Test
void helloWorld() {
var helloService = new HelloService();
assertDoesNotThrow(helloService::sayHelloWorld);
verify(System.getLogger("HelloService")).log(Level.INFO, "Hello World!");
}
Now this library implements services for JDK Platform Logging, Apache Commons Logging and SLF4J.
See more examples in the relevant modules of this project:
- for Apache Commons Logging in mock-loggers-commons-logging
- for JDK Platform Logging in mock-loggers-jdk-platform-logging
- for SLF4J in mock-loggers-slf4j
- Apache Log4j: Unit Testing in Maven
- Unit Test logback Using JUnit, it's old but gold
There are two projects which inspired me to make this library:
Please read Contributing.
See Changelog
Copyright 2024 Vitalij Berdinskih
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.