• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to modify how JUnit is outputting its results?

 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
James Adams
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic