How to make maven not show warnings when running jUnit tests that expect an exception?

When maven runs a jUnit test that expects an exception, this exception stack log is logged and displayed. Is there a way to disable logging. This is quite troubling since the assembly works well, but there are stacktraces in the output.

+3
source share
3 answers

The Maven Surefire 2.7.2 plugin does not. Are you using JUnit 3 or 4?

A test like this does not output a single stack, neither to the output of maven, nor to the report file:

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

In jUnit 3, such a test will also not print stacktrace. Your test looks 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");
}
+1
source

, , Surefire , .

0

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

log4j.additivity.org.hibernate=false  
0
source

All Articles