Thank you. This is exactly what I'm looking for. I have tried to use it, but don't see any way I can include it into my maven test dependency. Do I have to copy all the stuff I need and make a local test-library, or is it a maven GAV reference that I can include in my test-scope to get it.
Atle 2018-02-20 22:57 GMT+01:00 Matt Sicker <boa...@gmail.com>: > As for a random example: > > Config file: > https://github.com/apache/logging-log4j2/blob/master/ > log4j-core/src/test/resources/log4j-customLevel.xml > > Test class: > https://github.com/apache/logging-log4j2/blob/master/ > log4j-core/src/test/java/org/apache/logging/log4j/core/ > CustomLevelsTest.java > > JUnit rule: > https://github.com/apache/logging-log4j2/blob/master/ > log4j-core/src/test/java/org/apache/logging/log4j/junit/ > LoggerContextRule.java > > ListAppender: > https://github.com/apache/logging-log4j2/blob/master/ > log4j-core/src/test/java/org/apache/logging/log4j/test/ > appender/ListAppender.java > > On 20 February 2018 at 15:53, Matt Sicker <boa...@gmail.com> wrote: > > > If you add log4j-core:test (the test jar), there's a ListAppender built > in > > that we use extensively to verify logging messages in various scenarios. > If > > you add the list appender to your log4j2-test.xml file, then it'll take > > precedence over a normal log4j2.xml file. > > > > You can probably take a look at almost any random config file in > > log4j-core/src/test/resources/ and you'll find a list appender being > used. > > Then you can use the ListAppender class itself to locate that list, > though > > there's also the LoggerContextRule for JUnit 4.x that you can also use > (see > > one of the numerous unit tests in log4j-core for examples). > > > > On 20 February 2018 at 04:44, Atle Tokle <ato...@gmail.com> wrote: > > > >> I would like to know suggestions for best practices for unit-testing > that > >> logging is correctly performed in the code. > >> > >> I use Mockito, and have tried a few aproaches which I'm not pleased > with. > >> 1. I have tried static mock with Powermockito, but PowerMockito have > >> several bad effects and screws up code coverage report > >> 2. I have tried configure logging to console and capture System.out, but > >> that also is clumsy and have several bad effects, and is fragile if > >> someone > >> changes log4j-test.xml for any reason. > >> > >> Is it possible to programatic setup so logger created in code is backed > by > >> a Mockito Mock or Capture? > >> > >> Best Regards > >> Atle > >> > > > > > > > > -- > > Matt Sicker <boa...@gmail.com> > > > > > > -- > Matt Sicker <boa...@gmail.com> >