Is it possible to disable log4j exception output during jUnit tests?

You must disable log4j output to the console during jUnit tests, but all other log4j data must be included. During testing, there are many exceptions, checking the reaction of the method to the wrong argument, so the exception is normal.

+4
source share
2 answers

Create a new log4j properties file, called for example. log4j-test.properties with logging disabled. In the config of your order in POM, add argLine using -Dlog4j.configuration=log4j-test.properties .

+7
source

I know this question is quite old, but still relevant in my opinion, so I will add an alternative answer.

If you just want to disable (or reduce) logging for certain tests, or for some reason want to do this from code rather than creating a configuration file, you can do the following:

 RootLogger.getRootLogger().setLevel(Level.OFF); 
+3
source

All Articles