This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 98472 - Debug of jUnit4 tests doesn't work
Summary: Debug of jUnit4 tests doesn't work
Status: VERIFIED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: JUnit (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker with 1 vote (vote)
Assignee: Marian Petras
URL:
Keywords: UMBRELLA
: 104439 106211 109251 109512 111992 (view as bug list)
Depends on: 113718 113721 114046 114050
Blocks:
  Show dependency tree
 
Reported: 2007-03-21 13:59 UTC by Jiri Vagner
Modified: 2007-09-27 07:41 UTC (History)
5 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
strange-class.png (35.05 KB, image/png)
2007-03-21 14:53 UTC, Jiri Vagner
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jiri Vagner 2007-03-21 13:59:05 UTC
Action "Debug file" from popup menu above simple jUnit4.x test fails and
generates ...

1) warning(junit.framework.TestSuite$1)junit.framework.AssertionFailedError: No
tests found in testjavaapplication52.MainTest


NetBeans IDE Dev (Build 200703201900)
1.6.0_01; Java HotSpot(TM) Client VM 1.6.0_01-b04
Linux version 2.6.17-10-386 running on i386
Comment 1 Jiri Vagner 2007-03-21 14:53:53 UTC
Created attachment 39756 [details]
strange-class.png
Comment 2 Jiri Vagner 2007-03-21 14:56:53 UTC
Oups, wrong attachment. It belongs to issue 67548. I'm sorry.
Comment 3 Marian Petras 2007-03-23 17:28:57 UTC
It seems that projects cannot run JUnit 4.x tests in debug mode. Apparently, a
different Java class must be used.
Comment 4 Marian Petras 2007-05-22 13:21:25 UTC
*** Issue 104439 has been marked as a duplicate of this issue. ***
Comment 5 Marian Petras 2007-06-10 20:30:15 UTC
*** Issue 106211 has been marked as a duplicate of this issue. ***
Comment 6 fordfrog 2007-06-12 13:13:08 UTC
Workaround is to replace junit.textui.TestRunner with org.junit.runner.JUnitCore in build-impl.xml.

I think the solution should be:
1) if project is JDK 1.4 then use junit.textui.TestRunner in build-impl.xml and JUnit 3.8.x
2) if project is JDK 1.5+ then use org.junit.runner.JUnitCore in build-impl.xml and JUnit 4.x (this should work for both
JUnit 3.8.x tests and JUnit 4.x tests as JUnit 4.x is backward compatible though it requires JDK 1.5+ to run for both
types of tests)
Comment 7 fordfrog 2007-06-25 10:30:15 UTC
Just a note, I think that my workaround should be implemented in the code that generates build-impl.xml rather than
expecting users will modify their build-impl.xml by hand as the hand modification is not permanent in case
build-impl.xml is regenerated.
Comment 8 Jesse Glick 2007-06-25 14:56:42 UTC
Never edit build-impl.xml! (It should never be regenerated if there are user modifications, as a safety measure, but
editing it prevents unrelated parts from being updated.) Override desired targets in build.xml instead.
Comment 9 fordfrog 2007-06-25 17:37:32 UTC
That's the reason why I expect netbeans sets the class correctly in build-impl.xml rather than editing build-impl.xml or
overriding whole '-debug-start-debuggee-test' target just because classname argument of j2seproject3:debug element is
not set to org.junit.runner.JUnitCore as is needed for JUnit 4 tests.

AFAIK, the algorithm I suggested in the comment above should work and it doesn't seem to be difficult to implement, I
suppose the code just needs to check javac.source, if it's <1.5 then junit.textui.TestRunner would be put in, otherwise
org.junit.runner.JUnitCore would be put in.

Or is there a reason this was not fixed yet?
Comment 10 telespalla_filone 2007-07-04 22:06:41 UTC
Hi to everyone, do you know if M10 is affected to?
Thanks
Comment 11 peter_gillogley 2007-07-07 03:39:37 UTC
I have reproduced the issue on my M10.
To reproduce I took a JUnit 4 test that passes when "Run" (Shift-F6).
The test will not run in debug mode (Cntrl-shift-F5).
I did not attempt to fiddle with underlying build.XML files!
Comment 12 Peter Pis 2007-07-12 14:38:25 UTC
*** Issue 109251 has been marked as a duplicate of this issue. ***
Comment 13 Peter Pis 2007-07-12 14:40:12 UTC
*** Issue 109512 has been marked as a duplicate of this issue. ***
Comment 14 Jiri Vagner 2007-08-04 20:36:47 UTC
*** Issue 111992 has been marked as a duplicate of this issue. ***
Comment 15 Marian Petras 2007-08-22 09:53:51 UTC
The algorithm proposed by "fordfrog" on Jun 12 should work with a slight modification - check not only the JDK version
but also availability of the JUnit 4 library.
Comment 16 Marian Petras 2007-08-22 10:04:29 UTC
I just checked that the following modification of definition of target "-debug-start-debuggee-test" solves the issue
(added and modified lines are marked with a comment):

         <fail unless="test.class">Must select one file in the IDE or set test.class</fail>
 ADDED   <condition property="test.runner" value="org.junit.runner.JUnitCore"
 ADDED                                     else="junit.textui.TestRunner">
 ADDED       <and>
 ADDED           <available classname="java.lang.annotation.Annotation"/>
 ADDED           <available classname="org.junit.runner.JUnitCore" classpath="${debug.test.classpath}"/>
 ADDED       </and>
 ADDED   </condition>
MODIFIED <j2seproject3:debug classname="${test.runner}" classpath="${debug.test.classpath}">
             <customize>
                 <syspropertyset>
                     <propertyref prefix="test-sys-prop."/>
                     <mapper from="test-sys-prop.*" to="*" type="glob"/>
                 </syspropertyset>
                 <arg line="${test.class}"/>
             </customize>
         </j2seproject3:debug>

The modification on the line marked as "MODIFIED" is that the hard-coded class name "junit.textui.TestRunner" is
replaced with reference "${test.runner}".
Comment 17 Marian Petras 2007-08-22 18:24:38 UTC
Another (and probably more elegant) solution is the following one which also solves issue #87395 ("debug-test does not
show results"):

         <fail unless="test.class">Must select one file in the IDE or set test.class</fail>
 ADDED   <mkdir dir="${build.test.results.dir}"/>   <!-- must exist prior to running tests -->
 ADDED   <property name="results.file" location="${build.test.results.dir}/TEST-${test.class}.xml"/>
MODIFIED <j2seproject3:debug classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner"
MODIFIED                     classpath="${ant.home}/lib/ant.jar:${ant.home}/lib/ant-junit.jar:${debug.test.classpath}">
             <customize>
                 <syspropertyset>
                     <propertyref prefix="test-sys-prop."/>
                     <mapper from="test-sys-prop.*" to="*" type="glob"/>
                 </syspropertyset>
MODIFIED         <arg value="${test.class}"/>
 ADDED           <arg value="filtertrace=true"/>
 ADDED           <arg value="showoutput=true"/>
 ADDED           <arg value="outputtoformatters=true"/>
 ADDED           <arg value="logtestlistenerevents=true"/>
 ADDED           <arg value="formatter=org.apache.tools.ant.taskdefs.optional.junit.BriefJUnitResultFormatter"/>
 ADDED           <arg
value="formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,${results.file}"/>
             </customize>
         </j2seproject3:debug>

It is more elegant in the aspect that there is no need to determine versions of JDK and JUnit.
The not as elegant side of the solution is the need to prepend the classpath with two Ant libraries.
Comment 18 Marian Petras 2007-08-24 12:33:27 UTC
Update (improved, inspired by the similar target in NetBeans projects' build files):

         <fail unless="test.class">Must select one file in the IDE or set test.class</fail>
 ADDED   <property name="test.report.file" location="${build.test.results.dir}/TEST-${test.class}.xml"/>
 ADDED   <delete file="${test.report.file}"/>
 ADDED   <mkdir dir="${build.test.results.dir}"/>   <!-- must exist, otherwise the XML formatter would fail -->
MODIFIED <j2seproject3:debug classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner"
MODIFIED                     classpath="${ant.home}/lib/ant.jar:${ant.home}/lib/ant-junit.jar:${debug.test.classpath}">
             <customize>
                 <syspropertyset>
                     <propertyref prefix="test-sys-prop."/>
                     <mapper from="test-sys-prop.*" to="*" type="glob"/>
                 </syspropertyset>
MODIFIED         <arg value="${test.class}"/>
 ADDED           <arg value="showoutput=true"/>
 ADDED           <arg value="formatter=org.apache.tools.ant.taskdefs.optional.junit.BriefJUnitResultFormatter"/>
 ADDED           <arg
value="formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,${test.report.file}"/>
             </customize>
         </j2seproject3:debug>
Comment 19 Marian Petras 2007-08-29 17:22:34 UTC
The necessary changes in J2SE project, Web project and both J2EE projects are done. Marking as FIXED.
Comment 20 Jiri Vagner 2007-08-30 10:19:51 UTC
Verified

Product Version: NetBeans IDE Dev (Build 200708300413)
Java: 1.5.0_12; Java HotSpot(TM) Client VM 1.5.0_12-b04
System: Linux version 2.6.20-16-generic running on i386; UTF-8; en_US (nb)
Comment 21 Jiri Vagner 2007-09-20 10:48:29 UTC
Issue is back.

Product Version: NetBeans IDE Dev (Build 20070920070410)
Java: 1.5.0_12; Java HotSpot(TM) Client VM 1.5.0_12-b04
System: Linux version 2.6.20-16-generic running on i386; UTF-8; en_US (nb)
Comment 22 Jiri Vagner 2007-09-20 13:56:25 UTC
Issue is back, but only in my head. I'm sorry, but after a few restarts and with clean userdir debuging of junit4 tests
works perfectly.
Comment 23 Marian Petras 2007-09-20 15:16:32 UTC
Thank you for the update. If I understand correctly, reopening of this bug was a mistake - so I change the status back
to FIXED. Feel free to reopen this issue again if I am incorrect.
Comment 24 Jiri Vagner 2007-09-27 07:40:36 UTC
Product Version: NetBeans IDE Dev (Build 20070927012459)
Java: 1.6.0_03-ea; Java HotSpot(TM) Client VM 1.6.0_03-ea-b01
System: Windows XP version 5.1 running on x86; Cp1250; cs_CZ (nb)
Comment 25 Jiri Vagner 2007-09-27 07:41:20 UTC
Verified

Product Version: NetBeans IDE Dev (Build 20070927012459)
Java: 1.6.0_03-ea; Java HotSpot(TM) Client VM 1.6.0_03-ea-b01
System: Windows XP version 5.1 running on x86; Cp1250; cs_CZ (nb)