| Author |
How to modify how JUnit is outputting its results?
|
James Adams
Ranch Hand
Joined: Sep 12, 2003
Posts: 188
|
|
I have inherited some code which runs a suite of JUnit test cases (via junit.textui.TestRunner.doRun(mySuite)) and outputs the results of the test case either as "." for a success, or ".F" for a failure, followed by the errors and a summary of the run results. So if I have three test cases which run at once, and the first and third succeed, then the output file looks like "..F." followed by the errors and a summary of how many successes/failures. What I would like instead is to have the report look something like this: test-01-01: success test-01-01: failure test-02-01: success <errors> <summary> I have looked at the JavaDoc for junit.textui.TestRunner and there is no way to specify how the final report comes out, more specifically no way to tell it to print the name of the test case and the result rather than either "." for success or ".F" for failures. Can anyone advise me how I can modify this behavior? Am I stuck and just need to write a parser to convert the "..F." to a meaningful report as to which tests succeeded or failed (as in the above example)? Thanks in advance for any suggestions. --James
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24051
|
|
|
It is possible to write your own TestListener implementation to get notification about each test that runs, but if I were you, I would look at the reporting capabilities that are built into the Ant JUnit tasks. See ant.apache.org to learn about Ant if you're not already using it.
|
[Jess in Action][AskingGoodQuestions]
|
 |
James Adams
Ranch Hand
Joined: Sep 12, 2003
Posts: 188
|
|
Thanks for the pointer. I am using <junit> and <junitreport> in tandem now and it gives me much better output! --James
|
 |
James Adams
Ranch Hand
Joined: Sep 12, 2003
Posts: 188
|
|
One thing further on this topic -- I ran my test suite with the full battery of test cases (~80) and my machine ran out of memory (java.lang.OutOfMemoryError: Java heap space). So I added the fork option (I tried both fork="yes" and fork="on") and when I run the tests after that modification to the build.xml I get only a single test which fails almost immediately. The error I see in the log file tells me that there's an InvocationTargetException: If I remove the fork option everything goes back to normal and the tests all run OK (assuming I abbreviate the number of tests being run to 10-20 test cases per run). Can anyone tell me what is going on here? --James
|
 |
 |
|
|
subject: How to modify how JUnit is outputting its results?
|
|
|