jameskennard / slf4j-junit

Home Page:http://jameskennard.github.io/slf4j-junit/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

slf4j-junit

[![Coverage Status](https://img.shields.io/codecov/c/github/jameskennard/slf4j-junit.svg)](https://codecov.io/github/jameskennard/slf4j-junit)

slf4j-junit enables verification of logging made with SLF4J.

Getting Started

We create a normal JUnit test, and we add a JUnit TestRule in order to enable the verification of logging within the test.

import org.junit.Rule;

import static uk.co.webamoeba.slf4j.junit.LogVerification.enableLogging;

public class SomeTest {

@Rule
public EnableLogging enableLogging = enableLogging();

}

We can now create a test, and verify that some logging has taken place:

import static uk.co.webamoeba.slf4j.junit.LogVerification.verifyLogger;
import static uk.co.webamoeba.slf4j.junit.log.Level.INFO;

...

public void shouldDoSomething() { // Given String someArgument = "Hello everyone!";

// When
something.doSomething(someArgument);

// Then
verifyLogger(Something.class).logged(INFO, "I saw the 'Hello everyone!'");

}

About

http://jameskennard.github.io/slf4j-junit/

License:MIT License


Languages

Language:Java 100.0%