Shaun Abram
Technology and Leadership Blog
Add log4j logging for a unit test in IntelliJ
In IntelliJ
- Click: Run -> Edit Configuration
- Select your test configuration (or add a new one)
- In VM parameters, add
-Dlog4j.configuration=file:/C:/dev/config/log4j.xml
(Or wherever your log4j properties file is)
That’s it. The test should now run with log4j logging (although obviously you need to have the necessary log4j jars available).
This example uses a windows file format, but will work equally well with *nix.
I use this approach for turning on MyBatis logging for individual tests. See here for a basic setup of a log4j.xml file to enable logging with MyBatis.
Tags: intellij, JUnit, log4j, mybatis, unittesting