Git Product home page Git Product logo

slf4j-mock's Introduction

SLF4J mock

Build Maven Central Quality Gate Status Lines of Code

Yet another way to testing logging in application which use SLF4J.

Features

  • this binding support for easy create Mockito mock for Logger
  • call to Logger can be delegated to instance of SimpleLogger, so we can create standard simplelogger.properties
  • support for testing and mocking MDC
  • light transitive dependencies - only slf4j-api and mockito-core
  • support testing in parallel in multi thread
  • all the Magic are done by Mockito plugins, so you don't need to directly use class from this library
  • ease use

Example of usage

Add dependency to your project:

<dependencies>
    <dependency>
        <groupId>org.simplify4u</groupId>
        <artifactId>slf4j-mock</artifactId>
        <version><!-- check relases page --><version>  
        <scope>test</scope>        
    </dependency>
<dependencies>

Please remember, that you can only have one SLF4J binding on classpath, in the most case you must replace org.slf4j:slf4j-simple by org.simplify4u:slf4j-mock.

Write test:

class MyTest {

    @Mock
    Logger logger;

    @InjectMocks
    Example sut;

    @Test
    public void logInfoShouldBeLogged() {

        // when
        sut.methodWithLogInfo(INFO_TEST_MESSAGE);

        // then
        verify(logger).info(INFO_TEST_MESSAGE);
        verifyNoMoreInteractions(logger);
    }
}

Project homepage

More information and examples you can find on site:

https://www.simplify4u.org/slf4j-mock/

slf4j-mock's People

Contributors

slawekjaranowski avatar dependabot[bot] avatar josedemouramachado avatar dependabot-preview[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.