I'd like to be able to switch the bindings for SLF4J for unit testing over to the simple version, but it seems there is no easy way to config this. Basically, my built project logs to a file and I'd like it to be console instead when unit testing.
I've used the antrun maven plugin before to do something like this with persistence.xml files, but that solution seems a bit heavy handed.
Does anyone out there have a solution to using alternate configs or bindings in unit tests?
TIA
A better approach is to facilitate your logging framework. Logback library for instance first searches for logback-test.xml
and if it is not available, it looks for logback.xml
. If you place logback-test.xml
in /src/test/resources
, it will be picked up for unit tests. In this file you configure console logging instead of file.
If you are still using Log4J, simply place log4j.xml
in /src/test/resources
- this folder is available on classpath before /src/main/resources
, so Log4J will use it instead of ordinary /src/main/resources
version, while still loading the latter version for final builds (/src/test/resources
isn't even available then).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With