Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
Bug 159256 - Groovy Unit tests cannot be run
Groovy Unit tests cannot be run
Status: RESOLVED FIXED
Product: groovy
Classification: Unclassified
Component: Editor
7.4
PC Windows 7
: P3 with 2 votes (vote)
: 7.3
Assigned To: Martin Janicek
issues@groovy
:
Depends on: 170252
Blocks:
  Show dependency treegraph
 
Reported: 2009-02-26 20:33 UTC by pniederw
Modified: 2014-07-16 12:23 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
:


Attachments
build-impl.xml patch (3.42 KB, application/octet-stream)
2012-05-21 09:29 UTC, Martin Janicek
Details
maven project that demonstrates skipping of tests when using maven-compiler-plugin 3.0 (32.05 KB, application/octet-stream)
2013-04-04 13:59 UTC, ronniespike
Details

Note You need to log in before you can comment on or make changes to this bug.
Description pniederw 2009-02-26 20:33:10 UTC
I cannot run any unit test written in Groovy. "Run -> Test File" is grayed out (so is "Run -> Compile File"). "Run ->
Test Project" gives "no tests executed". Tried with JUnit 3 extending TestCase, JUnit 3 extending GroovyTestCase, JUnit
4 with @Test, and JUnit 4 with custom @RunWith runner but without @Test (the latter is what I really need).

"Run -> Run Project" seems to work, at least for HelloWorld.groovy.
Comment 1 Petr Hejl 2009-05-21 14:43:22 UTC
Run/Test file from context menu works for me. I'll investigate further.
Comment 2 pniederw 2009-06-01 20:00:29 UTC
I've tried again with 6.7 RC1, but still no luck. Run -> Test File is grayed out. Run -> Run File is enabled, but reports "No tests executed". Here is my test 
class (it's both a GroovyTestCase and a JUnit 4 test at the same time):

package netbeansgroovytest

import org.junit.Test

class GroovyTest extends GroovyTestCase {
    @Test
    void testMe() {
        println "HIIIIIIIIIIII"
        assert false
    }
}
Comment 3 pniederw 2009-07-03 21:45:36 UTC
Tried again with 6.7 final, and I still can't run any unit test. Also I get exceptions when creating new Groovy classes, editor sometimes doesn't recognize 
Groovy files (I get a plain text editor), etc. etc. It's a pity but the Netbeans Groovy plugin is totally unusable.  
Comment 4 Petr Hejl 2009-07-27 16:15:42 UTC
Reproduced. There is a problem with ant integration.
Comment 5 pniederw 2009-09-29 21:32:32 UTC
P3 means no JUnit support in 6.8?
Comment 6 Martin Janicek 2011-12-06 08:14:50 UTC
Not sure if I'm able to reproduce original issue, but it seems to me that we have a problem with running tests for Groovy in general.

I've created simple Java project with one Java JUnit test and one Groovy test and when trying to Run/Test those files, there is no test result shown in JUnit runner panel.

This should be fixed. Setting TM --> 7.2
Comment 7 Martin Janicek 2011-12-07 13:48:16 UTC
Moving to Editor component
Comment 8 Martin Janicek 2011-12-07 16:13:19 UTC
For now if you need at least a workarround to able to run .groovy tests, you need to change your build.xml file and put these lines right behind import
line:

<target depends="init,compile-test,-pre-test-run" if="have.tests"
name="-do-test-run">
        <j2seproject3:junit testincludes="**/*Test.class"/>
    </target>

    <target name="-init-macrodef-junit">
        <macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3">
            <attribute default="${includes}" name="includes"/>
            <attribute default="${excludes}" name="excludes"/>
            <attribute default="**" name="testincludes"/>
            <sequential>
                <junit dir="${work.dir}" errorproperty="tests.failed"
failureproperty="tests.failed" fork="true" showoutput="true">
                    <batchtest todir="${build.test.results.dir}">
                        <fileset dir="${build.test.classes.dir}"
excludes="@{excludes},${excludes}" includes="@{includes}">
                            <filename name="@{testincludes}"/>
                        </fileset>
                    </batchtest>
                    <classpath>
                        <path path="${run.test.classpath}"/>
                    </classpath>
                    <syspropertyset>
                        <propertyref prefix="test-sys-prop."/>
                        <mapper from="test-sys-prop.*" to="*" type="glob"/>
                    </syspropertyset>
                    <formatter type="brief" usefile="false"/>
                    <formatter type="xml"/>
                    <jvmarg line="${run.jvmargs}"/>
                </junit>
            </sequential>
        </macrodef>
    </target>

Note that it has also some unpleasant side effects (for example you will not be able to Run single test). I'm working on fix right now..
Comment 9 frankberger 2012-03-05 22:26:24 UTC
After adding the code from above I get:

/home/fb/projects/BGB/build.xml:15: The prefix "j2seproject3" for element "j2seproject3:junit" is not bound.

any suggestions?
Comment 10 Martin Janicek 2012-03-06 07:34:22 UTC
Ye, my apologize. I forgot to tell that you also need to change root project element and add this attribute:

xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" 

..which means element might looks like:

<project name="TestGroovy" default="default" basedir="." xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3">
Comment 11 Martin Janicek 2012-05-21 09:29:35 UTC
Created attachment 119676 [details]
build-impl.xml patch
Comment 12 Martin Janicek 2012-05-21 09:34:34 UTC
I've attached new build-impl.xml patch. After the changes both Java and Groovy tests should work together in Ant based projects. It also solves the side effect problem with running single method test.

Can't say now if would be possible to integrate those changes into the 7.2.
Comment 13 Martin Janicek 2012-05-22 11:50:01 UTC
I was looking at Maven projects as well.
It's actually much more easier to get Groovy tests working in Maven based projects - there are few things that you need to do:

1] Add groovy dependency to pom.xml:

<dependency>
    <groupId>org.codehaus.groovy</groupId>
    <artifactId>groovy-all</artifactId>
    <version>1.8.6</version>
</dependency>

2] Add Groovy-Eclipse compiler plugin for maven[1] to pom.xml:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <compilerId>groovy-eclipse-compiler</compilerId>
                <verbose>true</verbose>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.codehaus.groovy</groupId>
                    <artifactId>groovy-eclipse-compiler</artifactId>
                    <version>2.6.0-01</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

3] Create folder in src/test/groovy/.. and create some Groovy JUnit test inside

--> As a result you should be able to run those Groovy JUnit tests together with standard Java JUnit tests



[1] Groovy-Eclipse compiler plugin for maven: http://docs.codehaus.org/display/GROOVY/Groovy-Eclipse+compiler+plugin+for+Maven#Groovy-EclipsecompilerpluginforMaven-Howtousethecompilerplugin---SettingupthePOM
Comment 15 ronniespike 2013-04-03 15:59:53 UTC
The following maven artifact combination works, but if I use maven-compiler-plugin 3.0, the tests are undetected:

maven-compiler-plugin 2.3.2
groovy-eclipse-compiler 2.7.0-01
junit 4.11
groovy-all 2.1.1
Comment 16 Martin Janicek 2013-04-04 08:05:03 UTC
Hi ronnie, could you please share simple project illustrating the problem so I'll be able to easily reproduce incorrect behavior? Thanks in advance
Comment 17 ronniespike 2013-04-04 13:59:49 UTC
Created attachment 133307 [details]
maven project that demonstrates skipping of tests when using maven-compiler-plugin 3.0

Test is run w/ maven-compiler-plugin 2.5.1 as well.
Comment 18 ronniespike 2013-04-08 22:18:30 UTC
Looks like my issue was placing the groovy test scripts in the default groovy test package (src/test/groovy). If I place them in a package below the default package (e.g. src/test/groovy/mypackage), the tests are run during a mvn clean install.
Comment 19 Martin Janicek 2013-04-22 08:35:33 UTC
Weird I'm able to test files even under the default package. For some reason I'm unable to unable to unpack your project, so I can't confirm it directly but I tried:

1. Create new Maven app
2. Update pom.xml to use versions you described in comment 15
3. Create new Groovy JUnit test in the default package
4. Run tests for the whole project

..as a result I can see two tests passed. Ronnie, is there anything else I need to do?
Comment 20 cpscofield 2014-05-28 14:40:48 UTC
Would it be correct to assume that as of Netbeans 7.4 that all of the problems discussed here have been fixed? I suspect the answer is 'no' as I am seeing the same issues with Groovy testing in Netbeans 7.4. Or do we have to make the same workarounds for 7.4?
Comment 21 Martin Janicek 2014-07-16 12:23:37 UTC
(In reply to cpscofield from comment #20)
> Would it be correct to assume that as of Netbeans 7.4 that all of the
> problems discussed here have been fixed? I suspect the answer is 'no' as I
> am seeing the same issues with Groovy testing in Netbeans 7.4. Or do we have
> to make the same workarounds for 7.4?

Hi, could you at least describe what are you missing or what is not working for you? Comment complaining about everything is not really useful for anyone.

Please, open another issue/issues with proper description of any kind of problem you are still facing and I will gladly take a look at it.

Thanks for understanding.


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo