Getting JUnit Source

Folks,

I'm sure this question has been asked and answered before, but my searches are turning up nothing. According to the IDEA documentation, IDEA uses JUnit 3.8.1. I need to get the source code for this version so that I can try to troubleshoot a problem where a test of mine is throwing an exception but nothing seems to be catching it and nothing is being logged out to the console. I need to look at the runProtected method and possibly set some breakpoints to see what's happening. Can anyone assist me in finding the source code for the exact version of JUnit that IDEA is using?

Regards,
Paul

2 comments

You can get all previous versions from the Sourceforge site. Go to:
http://sourceforge.net/project/showfiles.php?group_id=15278&package_id=12472
scroll down to the version you want and download the .zip file. It contains
the source as well as the binaries.

"Paul" <no_reply@jetbrains.com> wrote in message
news:5666704.1176989713870.JavaMail.itn@is.intellij.net...

Folks,

>

I'm sure this question has been asked and answered before, but my
searches are turning up nothing. According to the IDEA documentation,
IDEA uses JUnit 3.8.1. I need to get the source code for this version so
that I can try to troubleshoot a problem where a test of mine is throwing
an exception but nothing seems to be catching it and nothing is being
logged out to the console. I need to look at the runProtected method and
possibly set some breakpoints to see what's happening. Can anyone assist
me in finding the source code for the exact version of JUnit that IDEA is
using?

>

Regards,
Paul



0

Brad,

Thank you very much for the link. I couldn't seem to find that anywhere in any of my searches. All of the results I found brought me to the latest 4.x releases.

In any event, the source code helped me understand my problem and, in the process, I learned something interesting about Java and JUnit. I thought others might find this information useful, so I figured I would explain what was happening.

I have a unit test which is configured to throw an Exception like the following:

public void testing_1_2_3() throws Exception {
...
}

The TestCase that contains this method implements tearDown(). The tearDown() method has an assertion in it. In my situation, my testing_1_2_3 method was throwing an Exception and then the tearDown method's assertion was also failing. However, all I was seeing was the excetpion stacktrace and message for the assertion failure. The real reason for that assertion failure was because of the exception being thrown in testing_1_2_3. After poking around briefly, what I discovered about how JUnit is handling this is as follows.

JUnit has a TestResult class that calls out to th TestCase class to run its tests. It does so in a runProtected method that has the running of the tests surrounded by try/catch blocks. The TestCase API runs the test inside of a try/finally block, where the finally block executes the tearDown() method. So, if an exception is thrown while the test is run, the finally block that executes the tearDown method is called before the catch blocks in the runProtected method are hit. If the tearDown in turn throws an exception, that will percolate up to the catch blocks in the runProtected method, and the previous exception that was thrown in the TestCase will be silently lost and never logged out.

Regards,
Paul

0

Please sign in to leave a comment.