How to supress the stack trace found in the junit reports?

1,578 views
Skip to first unread message

Jerald paul

unread,
Sep 28, 2011, 5:14:59 AM9/28/11
to webd...@googlegroups.com
How to supress the stack trace found in the junit reports? I dont want my reports filled with stack traces. Please help
Thanks
jerald

darrell

unread,
Sep 28, 2011, 2:24:22 PM9/28/11
to webdriver
Do you want to eliminate the stack trace from existing in the junit
report xml file? Or do you just not want it displayed? Most the
software I have used for display junit test results have the ability
to hide the stack track on failed test cases. In development
environments there is a +/- button so you can collapse the tree view
and hide the stack trace. On systems like Hudson/Jenkins or
Confluence, the junit report plugins have a flag you can set so it
does not display the stack trace. For example, in Confluence you can
put debug=false in the input parameters and it will not display stack
trace information. I.e.

{junitreport:directory=file:///home/junitreport/reports/2011-09-28 |
reportdetail='all'|debug=false}

If on the other hand you just don't want the information in the xml
file, it depends on the runner you are using. The basic runner which
comes with JUnit doesn't have any switches that I'm aware of to
suppress the stack trace. If you cannot find a runner to suppress the
stack trace, you could process the files after the test cases have
run. The stack trace is list a <![CDATA]> tag inside the <error></
error> tag. You could just transform the xml by removing the <!
[CDATA]> tags inside the <error></error> tags (if they exist; tests
which pass will have no <error></error> section).

Jerald paul

unread,
Sep 29, 2011, 5:28:55 AM9/29/11
to webd...@googlegroups.com
I have read the junitreport ant tag options in the documentation and found noting to hide/remove the stack traces from the final reports. Actually i want to do some customization to my junit4 reports.

1) Add a description column for each and every testcase
2) Remove the stack trace information.

thanks
jerald

darrell

unread,
Sep 29, 2011, 9:34:27 AM9/29/11
to webdriver
Ant uses the core JUnit Runner which comes with the JUnit jar file.
Essentially, in the junit jar file is the code to find and execute
test cases based on the JUnit standard. You can get the source code
for JUnit from Kent Beck's git repository:

git clone http://github.com/KentBeck/junit.git

It looks like it was set up to build using Maven. So the source code
is located in src/main/java. The class which runs the test cases is
org.junit.runner.JUnitCore. So you can find it in src/main/java/org/
junit/runner. If you look at the source you can see it takes no
command line options and just finds and executes the test cases.

If you look at the JavaDocs for JUnit (http://kentbeck.github.com/
junit/javadoc/latest/), you'll see the org.junit.runner package has a
RunWith class. You can use the RunWith annotation to make JUnit use a
custom runner for each test case. You'd have to modify your test cases
to have the @RunWith annotation but things like Ant would
automatically use the custom runner if done correctly.

The other options are to look at the JUnit runner and modify it,
leave the information in there and write a custom display program to
display it without the stack trace or run the reports through a
transformer to remove the stack trace.

To add a description to each test case might limit your options.
Removing or hiding the stack trace can be done without altering the
runner but adding information would probably mean an annotation on the
test case which you want added to the report. This would require
modifying the runner or creating a custom runner. Not as clean but you
could have a transformer program that removes the stack trace from the
reports and scans the test case files for tags, much like javadoc
scans comments for tags, which could be added to the report as custom
tags.

Bottom line, you are going to have to do a little coding or get
something from someone who has added to the core junit.
Reply all
Reply to author
Forward
0 new messages