开发者

How to make maven not show warnings when running jUnit tests which expects exception?

开发者 https://www.devze.com 2023-03-11 07:19 出处:网络
When maven runs jUnit test which expects exption this exception\'s stack trace logged and shown in output. Is there is a way how to switch off logging of this. It is quite bothering since build r开发者

When maven runs jUnit test which expects exption this exception's stack trace logged and shown in output. Is there is a way how to switch off logging of this. It is quite bothering since build r开发者_开发知识库uns well but there is stacktraces in output.


The Maven Surefire Plugin 2.7.2 does not do that. Are you using JUnit 3 or 4?

A test like this does not print any stacktrace, neither in the maven output or in the report file:

@Test(expected = NumberFormatException.class)
public void testForExpectedExceptionWithAnnotation()
        throws Exception {
    Integer.parseInt("This should blow up...");
}

In jUnit 3, a test like this will also not print a stacktrace. Is your test like this?:

public testForExpectedException() throws Exception{
  try{
    Integer.parseInt("This should blow up...");
 }catch(NumberFormatException e){
     //Just ignore it or do some asserts you could need
 }  

 fail("Exceptions not thrown");
}


You should change the test method not to print the stack trace, since the Surefire runner only displays what is returned by running the test cases.


I had the same problem and to resolve it I added the following line in the log4j.properties used by my unit tests :

log4j.additivity.org.hibernate=false  
0

精彩评论

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

关注公众号