carrizo
carrizo

Reputation: 65

JUnit Eclipse - Display stack trace on success

I'm writing some unit tests in eclipse which expect exceptions to be thrown.

I wonder if there is an option to display the stack-trace when a test passes, it would be useful when you are writing test for the first time to check if the exception is been thrown really due to the case you are testing.

thanks!

Upvotes: 5

Views: 1491

Answers (2)

Dave Newton
Dave Newton

Reputation: 160211

You shouldn't need to do that.

Use the @Test annotation with an expected argument:

@Test(expected=MyAppException.class)

If the test does not throw the exception it's a test failure.

There should be an Eclipse view option to show test logging output, but in general, explicit logging from tests isn't valuable. You can also debug your test if you don't trust the JUnit annotations.

Upvotes: 3

Kelly S. French
Kelly S. French

Reputation: 12344

Why not put System.out.print() statements inside the catch block of the test? I'm not sure how else you want to display output from a test because they are typically built to be silent when they succeed since there are so many of them.

Have you thought about using log4j and log.debug()?

Upvotes: 1

Related Questions