开发者

Setting application log level in TestNG

I have an application that uses Commons Logging for logging. It's built with Maven, and uses TestNG for testing.

I'm trying to fine-tune the logging level during tests, but not having any luck - everything is set to INFO, no matter what I do.

I tried creating a logging.properties file on the classpath, and it does absolutely nothing. I also created a log4testng.properties file - this one is being read (I know this because TestNG showed an error after I deliberately introduced a syntax error into it) but the settings in it have no effect.

Any suggestions?


EDIT: I haven't figured out the underlying problem (why java.util.logging is ignoring my attempts to configure it) but I was ab开发者_开发技巧le to get what I want by making Log4j available during tests, then configuring that.


I found a workaround for this. Create your custom logging.properties in src/test/resources, then in a setup call, load it up as such:

@BeforeClass(alwaysRun = true)
protected void setUp() throws SecurityException, IOException
{
    FileInputStream fis = new FileInputStream(BaseRestTest.class.getResource("/logging.properties").getFile());
    LogManager.getLogManager().readConfiguration(fis);
}

This appears to re-configure the root logger after TestNG has pillaged it.


Mike,

You can adjust the log level in testng.xml:

<suite verbose="3"...  (up to 10)

TestNG doesn't use Log4J nor java.util.logging.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜