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 142579

Summary: Add support for execution/debugging of a single test method
Product: java Reporter: Marian Petras <mpetras>
Component: ProjectAssignee: Tomas Zezula <tzezula>
Status: STARTED ---    
Severity: blocker CC: jglick, junit-issues, lhanson
Priority: P2    
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: TASK Exception Reporter:
Bug Depends on:    
Bug Blocks: 72080, 142763    
Attachments: visual diff of suggested changes in build-impl.xml - run single test method
visual diff of suggested changes in build-impl.xml - debug single test method
visual diff of suggested changes in build-impl.xml - debug single test method - corrected
suggested patch (J2SEActionProvider.java, build-impl.xsl)

Description Marian Petras 2008-08-01 13:59:20 UTC
Change the ActionProvider such that actions org.netbeans.spi.project.SingleMethod.COMMAND_(RUN|DEBUG)_SINGLE_METHOD are
supported.
Comment 1 Jesse Glick 2008-08-01 19:57:45 UTC
Is this going to be implemented for 6.5? Is there a corresponding issue for apisupport/project? Seems misleading for
issue #72080 to be marked FIXED when in fact you cannot use it yet.
Comment 2 Marian Petras 2008-08-04 09:46:15 UTC
Partially implemented - for the case that "Compile on Save" is enabled.

Changeset Id:
bf6e5ac3b136
(http://hg.netbeans.org/main/rev/bf6e5ac3b136)
Comment 3 Marian Petras 2008-08-04 09:53:12 UTC
It is going to be implemented. I just filed an issue for apisupport/project: #142763.
Comment 4 Quality Engineering 2008-08-04 15:41:42 UTC
Integrated into 'main-golden', available in build *200808041401* on http://bits.netbeans.org/dev/nightly/
Changeset: http://hg.netbeans.org/main/rev/bf6e5ac3b136
User: Marian Petras <mpetras@netbeans.org>
Log: Partially implemented support for execution/debugging of a single test method (task #142579) - for "compile on save" only for now.
Comment 5 Jesse Glick 2008-08-04 19:18:21 UTC
Marian: It seems that "methodname" is now a permitted parameter for ProjectRunner.QUICK_TEST{,_DEBUG} yet this fact is
not documented. It needs to be.
Comment 6 Jesse Glick 2008-08-04 20:41:16 UTC
Marian: while Run Again seems to work, Debug runs all the tests in the suite in the debugger.
Comment 7 Jesse Glick 2008-08-04 20:47:38 UTC
FYI: adding comparable support to automatic projects, in contrib #8523feba7521.
Comment 8 Marian Petras 2008-08-06 15:07:50 UTC
I just found the cause of the issue when debugging. The problem is in the classpath. When a test is to be debugged, it
is started with the following command (template):

        <java classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner" fork="true"
                                                                                       dir="${work.dir}"
                                                                                       jvm="${platform.java}">
            <classpath>
                <path path="${ant.home}/lib/ant.jar:${ant.home}/lib/ant-junit.jar"/>
                <path path="${classpath-translated}"/>
            </classpath>
                    ...
                </java>

The substantial thing is that the classpath does not contain the Ant patch that modifies the JUnitTestRunner such that
it accepts (and uses) command-line argument "methods=...". The fix is to put the .jar containing the patch to the
classpath such that it is before "ant-junit.jar". To make it working also with other Ant patches, I will put it to the
beginning of the classpath:

            <classpath>
                <fileset dir="${ant.home}" includes="patches/*.jar"/>
                <path path="${ant.home}/lib/ant.jar:${ant.home}/lib/ant-junit.jar"/>
                <path path="${classpath-translated}"/>
            </classpath>
Comment 9 Jesse Glick 2008-08-06 15:13:19 UTC
<fileset dir="${ant.home}" includes="patches/*.jar"/> sounds good to me. I guess I should have opened a separate issue.
Comment 10 Marian Petras 2008-08-07 14:54:50 UTC
Separate issue against which module? I looked at the Ant build script and an ideal solution would be to define a
classpath for Ant and assign it a specific Id (<path id="...">). This path would contain ${ant.home}/lib/ant.jar and all
Ant patches. All the tasks could then use this path using <path refid="...">). But I do not know whether it is
acceptable as almost any change of Ant script is also an API change.
Comment 11 Marian Petras 2008-08-07 16:27:10 UTC
Created attachment 66831 [details]
visual diff of suggested changes in build-impl.xml - run single test method
Comment 12 Marian Petras 2008-08-07 16:27:48 UTC
Created attachment 66832 [details]
visual diff of suggested changes in build-impl.xml - debug single test method
Comment 13 Marian Petras 2008-08-07 19:18:10 UTC
Created attachment 66849 [details]
visual diff of suggested changes in build-impl.xml - debug single test method - corrected
Comment 14 Marian Petras 2008-08-07 19:20:20 UTC
Correction: The updated (corrected) diff is for "run single test method".
Comment 15 Marian Petras 2008-08-07 19:31:59 UTC
Created attachment 66850 [details]
suggested patch (J2SEActionProvider.java, build-impl.xsl)
Comment 16 Jesse Glick 2008-08-07 21:29:54 UTC
Oh, you are talking about running/debugging a single test method from the regular Ant script. I did not even realize
there was any plan to support that. I was talking about Quick Run/Debug on tests, which seems more useful and is anyway
much simpler to implement: to make Debug work from the JUnit Results Window you need only change

java.source.ant/src/org/netbeans/modules/java/source/ant/resources/junit-debug-snippet.xml

to include ant/patches/*.jar in the classpath.
Comment 17 Marian Petras 2008-08-08 09:49:54 UTC
I have already committed (but not pushed yet) the fix in junit-debug-snippet.xml.
Comment 18 Marian Petras 2008-08-08 10:32:31 UTC
I pushed the fix of junit-debug-snippet.xml:

http://hg.netbeans.org/main/rev/c9208633ed4e
Comment 19 Jesse Glick 2008-08-08 15:42:05 UTC
I can confirm that #c9208633ed4e enables debug single test method for Google Guice dev sources opened as an automatic
project.
Comment 20 Jesse Glick 2010-07-08 17:42:14 UTC
Already works with CoS enabled; just need it to be made to work also with CoS off (i.e. using build-impl.xml).