title: Force JUnit to Display Uncaught Exception Stack Traces
body: <p>Possibly this might be already obvious in the JUnit docs, but can't seem to find it, nor remember if there is a solution for what I'm about to describe.</p>
  
  <p>When I'm running my test cases via maven (<code>mvn test</code>), stack traces of unexpected exceptions are not shown in standard error at all. All I get is a message indicating that a test failed.</p>
  
  <p>If my code under test throws an unchecked exception, say a NPE, my test case output looks like this:</p>
  
  <pre><code>Tests in error:
    testFoo(bar.Foo)
  
  Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
  </code></pre>
  
  <p>If my test case declares it can throw an <code>Exception</code> object, and I wrap the run-time exception like this:</p>
  
  <pre><code>@Test
  public void testFoo() throws Exception
  {
    try{ // something funky
       throw new NullPointerException();
    } catch( RuntimeException ex ) {
        throw new Exception(ex);
    }
  }
  </code></pre>
  
  <p>Then we get this:</p>
  
  <pre><code>Tests in error:
    testFoo(bar.Foo): java.lang.NullPointerException
  
  Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
  </code></pre>
  
  <p>Now I'm getting something barely useful. However, I would like to see the full enchilada, the entire stack trace. But I don't seem to find a way to do so with JUnit other than kludging my test cases within a catch/try block to print the stack trace to standard error (ugly):</p>
  
  <pre><code>@Test
  public void testFoo() throws Exception
  {
    try{ // something funky
       throw new NullPointerException();
    } catch( RuntimeException ex ) {
        ex.printStackTrace(); // &lt;&lt; this works, but it is ugly.
        throw ex;
    }
  }
  </code></pre>
  
  <p>I hate doing this because it pollutes (IMO) my test case logic; and it is manual, and I have to do it for every test case (I rather put the elbow grease and do it so that I get a stack trace right there and there, than to need a stack trace and not have it.)</p>
  
  <p>Is there a way to utilize/tell JUnit so that it prints the stack trace of any uncaught exception without *having to rely on explicitly catching/printing stack traces <em>within my test case code</em>*?</p>
  
  <p>Thanks.</p>