Setting custom TestExecutionListener for all test classes, so I can log the stack trace of every exception/assertion thrown

StackOverflow https://stackoverflow.com/questions/4748008

Question

Hey, I'm using SpringJUnit4ClassRunner. By default, the TestContextManager.afterTestMethod() logs every exception or assertion thrown very briefly (just the message), like so:

testMethod = testDataDriven@DataDrivenAbstractTest, testException = [null]]

I would like to write a custom TestExecutionListener that logs all exceptions thrown by any test in my project. I don't want to have to remember to annotate each of my test classes with @TestExecutionListeners.

Can I somehow do it globally? am I on the right track?

Thanks.

Was it helpful?

Solution

No, you can't do it globally, but you can write a base class that uses the TestExecutionListener and let all other test classes extend it.

Or you can extend SpringJUnit4ClassRunner to do your stuff and run your tests with @Runwith(YourCustomSpringJUnit4ClassRunner.class)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top