Need to disable log4j output to console during jUnit tests running but all other log4j output should be enable. There are lot exceptions during testing while checking method reaction on incorrect argument, so exception is ok.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Create a new log4j properties file called e.g. log4j-test.properties
with logging disabled. In your surefire config in the POM, add argLine
with -Dlog4j.configuration=log4j-test.properties
.
回答2:
I know this question is quite old, but still relevant in my opinion, so I'll add an alternative answer.
If you just want to disable (or reduce) logging for certain tests, or for some reason want to do it from code rather than creating a config file, you could do the following:
RootLogger.getRootLogger().setLevel(Level.OFF);