I am using JUnit4 and organized all my tests in a Test suite, annotated with a @RunWith(Suite.class) annotation.
Now I want to register a custom logger to JUnit, so at each beginning and completion of each test a log message is printed.
I already found the RunNotifier and RunListener classes, but don't know how I can add my listener from within my TestSuite definition to JUnit.
Any ideas?
I think you've already hinted at the solution. Write your own runner and use the @RunWith annotation to specify your runner for your test/suite. That should allow you to see your output even when running in eclipse/ant as junit will use the annotation.
You can instantiate a JUnitCore object and call addListener() before calling run. Not sure if there is a better way with an annotation, but I haven't come across one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With