I am working with JUnit and I have this idea which I want to implement. I want to write a runner that will log the results of each test to an excel or a text file so that i can attach it in my reports. What do i need to learn to get started
Asked
Active
Viewed 1,851 times
1 Answers
4
Two alternatives
Write a RunListener and use it like:
public void main(String... args) { JUnitCore core= new JUnitCore(); core.addListener(new MyRunListener()); core.run(MyTestClass.class); }
Write a RunListener again. But this time extend an org.junit.runner.Runner implementation and override its run method like
@Override public void run(RunNotifier notifier) { notifier.addListener(new MyRunNotifier()); super.run(notifier); }
Second approach can also be used in tests with @RunWith(MyRunner.class) annotation.

ayortanli
- 109
- 11
-
In solution (2) the super.run doesn't work, because Runner is abstract. did you mean "ParentRunner"? – John Henckel Aug 28 '14 at 21:46
-
As I mentioned, 'extend a Runner implementation'. So super.run will call the extended ParentRunner. – ayortanli Sep 02 '14 at 08:05