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.
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
Created attachment 39756 [details] strange-class.png
Oups, wrong attachment. It belongs to issue 67548. I'm sorry.
It seems that projects cannot run JUnit 4.x tests in debug mode. Apparently, a different Java class must be used.
*** Issue 104439 has been marked as a duplicate of this issue. ***
*** Issue 106211 has been marked as a duplicate of this issue. ***
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)
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.
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.
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?
Hi to everyone, do you know if M10 is affected to? Thanks
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!
*** Issue 109251 has been marked as a duplicate of this issue. ***
*** Issue 109512 has been marked as a duplicate of this issue. ***
*** Issue 111992 has been marked as a duplicate of this issue. ***
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.
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}".
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.
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>
The necessary changes in J2SE project, Web project and both J2EE projects are done. Marking as FIXED.
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)
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)
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.
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.
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)
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)