|
Re: design issue: msg#00199java.junit.user
> Vladimir is probably a better person to answer these questions than I > am, since he has worked more closely with the API from a developer's > point of view. Vladimir? :) Thanks J.B. I'll answer :-) From what I saw from your code, I guess that you want to write the errors/failures into a log file. First question to answer: is TestListener the right solution? In this case, I would rather go with the JUnitReport task from Ant. Another solution would be to pipe the TextUIRunner into a file (with junit.textrunner ... > result.log). But I imagine that you really want to use a TestListener and the task is to record all errors/failures into a log file. The quickest solution I found (with the version 3.7 of JUnit) is the following: package junit.textui; // (1) public class VBORunner extends TestRunner { public TestResult doRun(Test suite, boolean wait) { TestResult result= createTestResult(); result.addListener(new VBOListener()); // (2) result.addListener(this); long startTime= System.currentTimeMillis(); suite.run(result); long endTime= System.currentTimeMillis(); long runTime= endTime-startTime; writer().println(); writer().println("Time: "+elapsedTimeAsString(runTime)); print(result); writer().println(); pause(wait); return result; } public static void main(String args[]) { TestRunner aTestRunner= new VBORunner(); // (3) try { TestResult r= aTestRunner.start(args); // (4) if (!r.wasSuccessful()) System.exit(-1); System.exit(0); } catch(Exception e) { System.err.println(e.getMessage()); System.exit(-2); } } } (1) the VBORunner class must be placed into the junit.textui package since the method start (4) is defined as protected (2) only the TestResult object allows several listeners, so we will use it to add our listener (VBOListener simply implements TestListener). The version 3.8 introduces the TestRunListener, but there's no mechanism yet to specify several TestRunListeners]. (3) I had to overwrite the main method to create my special VBORunner. This class can only be used with the console but the idea is the same for the other runners. There are several other possibilities but I think that this one is the quickest. Anyone has another idea? Hope this help -Vladimir -- Vladimir Bossicard www.bossicard.com
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: design issue, noneofyer42businessbub |
|---|---|
| Next by Date: | how to show a longer stack trace on the report, Emerson Cargnin - MSA |
| Previous by Thread: | Re: design issue, J. B. Rainsberger |
| Next by Thread: | Re: design issue, noneofyer42businessbub |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |