开发者

Add logging listener for whole test suite

开发者 https://www.devze.com 2023-03-09 18:37 出处:网络
I am using JUnit4 and organized all my tests in a Test suite, annotated with a @RunWith(Suite.class) annotation.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号