SLF4J JUnit

Library to make testing of logging behaviour easier when using SLF4J and JUnit

License

License

Categories

Categories

JUnit Unit Testing SLF4J Application Layer Libs Logging
GroupId

GroupId

uk.co.webamoeba.slf4j
ArtifactId

ArtifactId

slf4j-junit
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

SLF4J JUnit
Library to make testing of logging behaviour easier when using SLF4J and JUnit
Project URL

Project URL

https://github.com/jameskennard/slf4j-junit
Source Code Management

Source Code Management

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

Download slf4j-junit

How to add to project

<!-- https://jarcasting.com/artifacts/uk.co.webamoeba.slf4j/slf4j-junit/ -->
<dependency>
    <groupId>uk.co.webamoeba.slf4j</groupId>
    <artifactId>slf4j-junit</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/uk.co.webamoeba.slf4j/slf4j-junit/
implementation 'uk.co.webamoeba.slf4j:slf4j-junit:1.0.0'
// https://jarcasting.com/artifacts/uk.co.webamoeba.slf4j/slf4j-junit/
implementation ("uk.co.webamoeba.slf4j:slf4j-junit:1.0.0")
'uk.co.webamoeba.slf4j:slf4j-junit:jar:1.0.0'
<dependency org="uk.co.webamoeba.slf4j" name="slf4j-junit" rev="1.0.0">
  <artifact name="slf4j-junit" type="jar" />
</dependency>
@Grapes(
@Grab(group='uk.co.webamoeba.slf4j', module='slf4j-junit', version='1.0.0')
)
libraryDependencies += "uk.co.webamoeba.slf4j" % "slf4j-junit" % "1.0.0"
[uk.co.webamoeba.slf4j/slf4j-junit "1.0.0"]

Dependencies

provided (2)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.7
junit : junit jar 4.12

test (1)

Group / Artifact Type Version
org.mockito : mockito-core jar 1.10.19

Project Modules

There are no modules declared in this project.

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!'");

}

Versions

Version
1.0.0