groovy

Groovy Ant Task is not executing Groovy Test Cases as the Command Line does

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.5.3
  • Fix Version/s: 1.5.5, 1.6-beta-1
  • Component/s: Ant integration
  • Labels:
    None
  • Environment:
    Mac OS X 10.5, Java 1.5
  • Number of attachments :
    1

Description

Trying to execute a Groovy Test Case using the Groovy Ant Tasks fails because it is complaining about a missing main() method:

groovy.lang.MissingMethodException: No signature of method: org.guilder.plugin.PluginTest.main() is applicable for argument types: ([Ljava.lang.String values: {[]}
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:54)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:59)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:169)
at org.guilder.plugin.PluginTest.invokeMethod(PluginTest.groovy)
at org.codehaus.groovy.runtime.InvokerHelper$2.run(InvokerHelper.java:426)
at org.codehaus.groovy.ant.Groovy.execGroovy(Groovy.java:348)

This happens when I use Ant through the command line as well as using AntBuilder. This is the build.xml script I use:

project>
<path id="my.classpath">
<fileset dir="/Java/groovy/lib">
<include name="*/.jar"/>
</fileset>
</path>
<target name="run">
<taskdef name="groovy"
classname="org.codehaus.groovy.ant.Groovy"
classpathref="my.classpath"/>
<groovy src="org/guilder/plugin/PluginTest.groovy">
</groovy>
</target>
</project>

Executing the Script through: 'groovy org/guilder/plugin/PluginTest.groovy' it works fine.

Unfortunately I could not figure out how the Groovy Command Line tool does handle that otherwise I would created a patch.

Any ideas?

-Andy

Issue Links

Activity

Hide
Andreas Schaefer added a comment -

And by the way I ran into another issue with the Groovy jUnit Tests. Using the GroovyTestCase does fail on me because it cannot find the jUnit Test Case class. This is an issue for me because I fire up groovy without jUnit in its class path and then add it dynamically at runtime. Unfortunately the GroovyTestCase is attached to the class loader that stated Groovy and so I cannot add the jUnit archive on the same class loader level. Thus I get a No Class Def Found Error.

-Andy

Show
Andreas Schaefer added a comment - And by the way I ran into another issue with the Groovy jUnit Tests. Using the GroovyTestCase does fail on me because it cannot find the jUnit Test Case class. This is an issue for me because I fire up groovy without jUnit in its class path and then add it dynamically at runtime. Unfortunately the GroovyTestCase is attached to the class loader that stated Groovy and so I cannot add the jUnit archive on the same class loader level. Thus I get a No Class Def Found Error. -Andy
Hide
Jim White added a comment -

I don't have the fix for the Groovy Ant task, but I'll attach an Ant script that shows a way to work around the problem for the moment.

Show
Jim White added a comment - I don't have the fix for the Groovy Ant task, but I'll attach an Ant script that shows a way to work around the problem for the moment.
Hide
Jim White added a comment -

A sample Ant script that shows a way to call a GroovyTestCase from the Groovy Ant task.

Show
Jim White added a comment - A sample Ant script that shows a way to call a GroovyTestCase from the Groovy Ant task.
Hide
Paul King added a comment - - edited

Using a slightly modified version of Jim's script:

build.xml
<project name="groovytest" default="groovy-junit">
    <property name="dep-groovy.dir" value="C:/Downloads/groovy.codehaus.org/svntrunk-groovy/groovy-core/target/install"/>

    <taskdef name="groovy"
            classname="org.codehaus.groovy.ant.Groovy">
        <classpath>
            <fileset dir="${dep-groovy.dir}/embeddable">
                <include name="groovy-all-1.6-beta-1-SNAPSHOT.jar"/>
            </fileset>
            <fileset dir="${dep-groovy.dir}/lib">
                <include name="junit-3.8.2.jar"/>
            </fileset>
        </classpath>
    </taskdef>

    <target name="groovy-junit">
        <groovy>
           def loader = new GroovyClassLoader(getClass().getClassLoader())
           def testClass = loader.parseClass(new File('TestCase.groovy'))
           println testClass
           junit.textui.TestRunner.run(testClass)
        </groovy>
    </target>
</project>

And with this file:

TestCase.groovy
class TestCase extends GroovyTestCase {
    void testPlus() {
        assert 6 == 3 + 3
    }
}

I get this result:

> ant
Buildfile: build.xml

groovy-junit:
   [groovy] class TestCase
   [groovy] .
   [groovy] Time: 0.015
   [groovy]
   [groovy] OK (1 test)
   [groovy]

BUILD SUCCESSFUL
Total time: 1 second
Show
Paul King added a comment - - edited Using a slightly modified version of Jim's script:
build.xml
<project name="groovytest" default="groovy-junit">
    <property name="dep-groovy.dir" value="C:/Downloads/groovy.codehaus.org/svntrunk-groovy/groovy-core/target/install"/>

    <taskdef name="groovy"
            classname="org.codehaus.groovy.ant.Groovy">
        <classpath>
            <fileset dir="${dep-groovy.dir}/embeddable">
                <include name="groovy-all-1.6-beta-1-SNAPSHOT.jar"/>
            </fileset>
            <fileset dir="${dep-groovy.dir}/lib">
                <include name="junit-3.8.2.jar"/>
            </fileset>
        </classpath>
    </taskdef>

    <target name="groovy-junit">
        <groovy>
           def loader = new GroovyClassLoader(getClass().getClassLoader())
           def testClass = loader.parseClass(new File('TestCase.groovy'))
           println testClass
           junit.textui.TestRunner.run(testClass)
        </groovy>
    </target>
</project>
And with this file:
TestCase.groovy
class TestCase extends GroovyTestCase {
    void testPlus() {
        assert 6 == 3 + 3
    }
}
I get this result:
> ant
Buildfile: build.xml

groovy-junit:
   [groovy] class TestCase
   [groovy] .
   [groovy] Time: 0.015
   [groovy]
   [groovy] OK (1 test)
   [groovy]

BUILD SUCCESSFUL
Total time: 1 second
Hide
Paul King added a comment -

Meant to close another issue.

Show
Paul King added a comment - Meant to close another issue.
Hide
Paul King added a comment - - edited

Now calls the GroovyShell run method if a script isn't found. The special ant properties that the normal groovy task passes through via the binding are not available in this case.

Show
Paul King added a comment - - edited Now calls the GroovyShell run method if a script isn't found. The special ant properties that the normal groovy task passes through via the binding are not available in this case.
Hide
Paul King added a comment - - edited

Some examples of usage until these examples make it into the doco:

JUnit 3.x:

<target name="groovy-junit">
        <groovy>
        class TestCase extends GroovyTestCase {
            void testPlus() {
                assert 6 == 3 + 3
            }
            void testMult() {
                assert 6 == 3 * 2
            }
        }
        </groovy>
    </target>

Output:

groovy-junit:
   [groovy] ..
   [groovy] Time: 0.016
   [groovy]
   [groovy] OK (2 tests)
   [groovy]

BUILD SUCCESSFUL

JUnit 4.4:

<target name="groovy-junit44">
        <groovy classpathref="groovy-junit44.path">
        import org.junit.Test
        import static org.junit.Assert.assertEquals

        class ArithmeticTest {
            @Test
            void additionIsWorking() {
                assertEquals 4, 2+2
            }

            @Test(expected=ArithmeticException)
            void divideByZero() {
                println 1/0
            }
        }
        </groovy>
    </target>

Output:

groovy-junit44:
   [groovy] JUnit 4 Runner, Tests: 2, Failures: 0, Time: 16

BUILD SUCCESSFUL

TestNG:

<target name="groovy-testng">
        <groovy classpathref="groovy-testng.path">
        import org.testng.annotations.Test
        import org.testng.annotations.ExpectedExceptions
        import static org.testng.Assert.assertEquals

        class ArithmeticTestScriptNG {
            @Test
            void additionIsWorking() {
                assertEquals 4, 2 + 2, "plus is broken"
            }

            @Test
            void subtractionIsWorking() {
                assert 6 == 8 - 2, "minus is broken"
            }

            // will never be called
            @Test(enabled=false)
            void magicHappens() {
                assertEquals 1, 2
            }

            @Test(expectedExceptions=[ArithmeticException])
            void divideByZero() {
                println 1/0
            }
        }
        </groovy>
    </target>

Output:

groovy-testng:
   [groovy] [Parser] Running:
   [groovy]   Command line suite
   [groovy]
   [groovy]
   [groovy] ===============================================
   [groovy] Command line suite
   [groovy] Total tests run: 3, Failures: 0, Skips: 0
   [groovy] ===============================================
   [groovy]

BUILD SUCCESSFUL
Show
Paul King added a comment - - edited Some examples of usage until these examples make it into the doco: JUnit 3.x:
<target name="groovy-junit">
        <groovy>
        class TestCase extends GroovyTestCase {
            void testPlus() {
                assert 6 == 3 + 3
            }
            void testMult() {
                assert 6 == 3 * 2
            }
        }
        </groovy>
    </target>
Output:
groovy-junit:
   [groovy] ..
   [groovy] Time: 0.016
   [groovy]
   [groovy] OK (2 tests)
   [groovy]

BUILD SUCCESSFUL
JUnit 4.4:
<target name="groovy-junit44">
        <groovy classpathref="groovy-junit44.path">
        import org.junit.Test
        import static org.junit.Assert.assertEquals

        class ArithmeticTest {
            @Test
            void additionIsWorking() {
                assertEquals 4, 2+2
            }

            @Test(expected=ArithmeticException)
            void divideByZero() {
                println 1/0
            }
        }
        </groovy>
    </target>
Output:
groovy-junit44:
   [groovy] JUnit 4 Runner, Tests: 2, Failures: 0, Time: 16

BUILD SUCCESSFUL
TestNG:
<target name="groovy-testng">
        <groovy classpathref="groovy-testng.path">
        import org.testng.annotations.Test
        import org.testng.annotations.ExpectedExceptions
        import static org.testng.Assert.assertEquals

        class ArithmeticTestScriptNG {
            @Test
            void additionIsWorking() {
                assertEquals 4, 2 + 2, "plus is broken"
            }

            @Test
            void subtractionIsWorking() {
                assert 6 == 8 - 2, "minus is broken"
            }

            // will never be called
            @Test(enabled=false)
            void magicHappens() {
                assertEquals 1, 2
            }

            @Test(expectedExceptions=[ArithmeticException])
            void divideByZero() {
                println 1/0
            }
        }
        </groovy>
    </target>
Output:
groovy-testng:
   [groovy] [Parser] Running:
   [groovy]   Command line suite
   [groovy]
   [groovy]
   [groovy] ===============================================
   [groovy] Command line suite
   [groovy] Total tests run: 3, Failures: 0, Skips: 0
   [groovy] ===============================================
   [groovy]

BUILD SUCCESSFUL

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: