You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Ed <ej...@summitbid.com> on 2008/11/17 04:35:06 UTC

Adding a GroovyTestCase to a maven project

I'd like to use Groovy for unit testing a maven project, but I'm not
sure how to configure the project so the groovy file containing the
GroovyTestCase will compile and execute.

I added the groovy-all-1.5.6.jar as a dependency in the top level pom.
                <dependency>
			<groupId>org.codehaus.groovy</groupId>
			<artifactId>groovy-all</artifactId>
			<version>1.5.6</version>
			<scope>test</scope>
		</dependency>

I also added a GroovyTestCase file to src/test/java, and of course, it
did not execute.

I added the file to a src/test/groovy folder and it still did not execute.

Is the only way to get this to work by using the GMaven plugin?

-- 
Ed

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Adding a GroovyTestCase to a maven project

Posted by Luke Daley <ld...@ldaley.com>.
On 18/11/2008, at 10:30 AM, Ed wrote:

> Thanks. That did the trick when executing from the command line.
>
> Now I need to figure out how to execute the unit tests from within  
> eclipse.
> The groovy unit tests are in the src/main/groovy package path and  
> the groovy
> test class files are in the correct target/test-classes/ classpath,  
> but when
> I try to "run as" JUnit test I get:
>
> Groovy Runner Error
> Error running GroovyNetworkFilterTest.groovy failed to find a class  
> file,
> ensure the Groovy output folder is on the classpath.
>
> My eclipse .classpath looks like this:
>  <?xml version="1.0" encoding="UTF-8"?>
> <classpath>
>     <classpathentry kind="src" path="src/main/java"/>
>     <classpathentry excluding="**/*.java" kind="src"
> path="src/main/resources"/>
>    * <classpathentry kind="src" output="target/test-classes"
> path="src/test/java"/>
>     <classpathentry kind="src" output="target/test-classes"
> path="src/test/groovy"/>*
>     <classpathentry excluding="**/*.java" kind="src"
> output="target/test-classes" path="src/test/resources"/>
>     <classpathentry kind="con"
> path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
>     <classpathentry kind="var"
> path="M2_REPO/com/comcast/comcast-common-util/1.5.2/comcast-common- 
> util-1.5.2.jar"/>
>     <classpathentry kind="var"
> path="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14.jar"/>
>     <classpathentry kind="var"
> path="M2_REPO/jpcap/jpcap/0.7/jpcap-0.7.jar"/>
>     <classpathentry kind="var"
> path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
>     <classpathentry exported="true" kind="con" path="GROOVY_SUPPORT"/>
>     <classpathentry kind="output" path="target/classes"/>
> </classpath>
>
> ...Any ideas?

None here sorry.

--

LD.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Adding a GroovyTestCase to a maven project

Posted by Ed <ej...@summitbid.com>.
Thanks. That did the trick when executing from the command line.

Now I need to figure out how to execute the unit tests from within eclipse.
The groovy unit tests are in the src/main/groovy package path and the groovy
test class files are in the correct target/test-classes/ classpath, but when
I try to "run as" JUnit test I get:

Groovy Runner Error
Error running GroovyNetworkFilterTest.groovy failed to find a class file,
ensure the Groovy output folder is on the classpath.

My eclipse .classpath looks like this:
 <?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src/main/java"/>
    <classpathentry excluding="**/*.java" kind="src"
path="src/main/resources"/>
   * <classpathentry kind="src" output="target/test-classes"
path="src/test/java"/>
    <classpathentry kind="src" output="target/test-classes"
path="src/test/groovy"/>*
    <classpathentry excluding="**/*.java" kind="src"
output="target/test-classes" path="src/test/resources"/>
    <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind="var"
path="M2_REPO/com/comcast/comcast-common-util/1.5.2/comcast-common-util-1.5.2.jar"/>
    <classpathentry kind="var"
path="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14.jar"/>
    <classpathentry kind="var"
path="M2_REPO/jpcap/jpcap/0.7/jpcap-0.7.jar"/>
    <classpathentry kind="var"
path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
    <classpathentry exported="true" kind="con" path="GROOVY_SUPPORT"/>
    <classpathentry kind="output" path="target/classes"/>
</classpath>

...Any ideas?



On Sun, Nov 16, 2008 at 10:06 PM, Luke Daley <ld...@ldaley.com> wrote:
>
> On 17/11/2008, at 2:54 PM, Ed wrote:
>
>> What's the recipe? Seems like there's alot to do.
>
> All I had to do was drop the following in <build> -> <plugins>…
>
> <plugin>
>    <groupId>org.codehaus.groovy.maven</groupId>
>    <artifactId>gmaven-plugin</artifactId>
>    <version>1.0-rc-3</version>
>    <extensions>true</extensions>
>    <executions>
>        <execution>
>            <goals>
>                <goal>generateStubs</goal>
>                <goal>compile</goal>
>                <goal>generateTestStubs</goal>
>                <goal>testCompile</goal>
>            </goals>
>        </execution>
>    </executions>
> </plugin>
>
> You can probably drop the 'generateStubs' and 'compile' executions if you
> only want it for testing.
>
> --
>
> LD.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>



-- 
Ed

Re: Adding a GroovyTestCase to a maven project

Posted by Luke Daley <ld...@ldaley.com>.
On 17/11/2008, at 2:54 PM, Ed wrote:

> What's the recipe? Seems like there's alot to do.

All I had to do was drop the following in <build> -> <plugins>…

<plugin>
     <groupId>org.codehaus.groovy.maven</groupId>
     <artifactId>gmaven-plugin</artifactId>
     <version>1.0-rc-3</version>
     <extensions>true</extensions>
     <executions>
         <execution>
             <goals>
                 <goal>generateStubs</goal>
                 <goal>compile</goal>
                 <goal>generateTestStubs</goal>
                 <goal>testCompile</goal>
             </goals>
         </execution>
     </executions>
</plugin>

You can probably drop the ‘generateStubs’ and ‘compile’ executions if  
you only want it for testing.

--

LD.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Adding a GroovyTestCase to a maven project

Posted by Ed <ej...@summitbid.com>.
Thanks for the encouragement...

What's the recipe? Seems like there's alot to do.

I added a couple more dependencies for the GMaven runtime and the gmaven mojo:

         <dependency>
                <groupId>org.codehaus.groovy.maven</groupId>
                <artifactId>gmaven-mojo</artifactId>
                <version>1.0-rc-3</version>
        </dependency>
        <dependency>
                <groupId>org.codehaus.groovy.maven.runtime</groupId>
                <artifactId>gmaven-runtime-default</artifactId>
                <version>1.0-rc-3</version>
        </dependency>

and

      <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.groovy.maven</groupId>
                    <artifactId>gmaven-plugin</artifactId>
                    <version>1.0-rc-3</version>
                </plugin>
            </plugins>
        </pluginManagement>

In the build section

I tried to install the jar file to my local repository:

mvn -e install:install-file
-DgroupId=org.codehaus.groovy.maven.runtime
-DartifactId=gmaven-runtime-default -Dversion=1.0-rc-3 -Dpackaging=jar
-Dfile=c:/Documents and
Settings/eyoun/Desktop/gmaven-runtime-default-1.0-rc-3.jar
mvn -e install:install-file
-DgroupId=org.codehaus.groovy.maven.runtime
-DartifactId=gmaven-runtime-default -Dversion=1.0-rc-3 -Dpackaging=jar
-Dfile=c:/Documents and
Settings/eyoun/Desktop/gmaven-runtime-default-1.0-rc-3.jar
+ Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'install'.
[INFO] com.octo.mtg: checking for updates from central-plugins
[WARNING] repository metadata for: 'com.octo.mtg' could not be
retrieved from repository: central-plugins due to an error: Error
transferring file
[INFO] Repository 'central-plugins' will be blacklisted
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Invalid task 'and': you must specify a valid lifecycle phase,
or a goal in the format plugin:goal or
pluginGroupId:pluginArtifactId:pluginVersion:goal
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.BuildFailureException: Invalid task 'and': you must
specify a valid lifecycle phase, or a goal in the format plugin:goal
or pluginGroupId:pluginArtifactId:pluginVersion:goal
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.getMojoDescriptor(DefaultLifecycleExecutor.java:1521)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.segmentTaskListByAggregationNeeds(DefaultLifecycleExecutor.java:405)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:137)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:287)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
	at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
	at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
	at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 22 seconds
[INFO] Finished at: Sun Nov 16 21:51:27 MST 2008
[INFO] Final Memory: 3M/6M
[INFO] ------------------------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Adding a GroovyTestCase to a maven project

Posted by Luke Daley <ld...@ldaley.com>.
On 17/11/2008, at 1:35 PM, Ed wrote:

> I'd like to use Groovy for unit testing a maven project, but I'm not
> sure how to configure the project so the groovy file containing the
> GroovyTestCase will compile and execute.
>
> I added the groovy-all-1.5.6.jar as a dependency in the top level pom.
>                 <dependency>
> 			<groupId>org.codehaus.groovy</groupId>
> 			<artifactId>groovy-all</artifactId>
> 			<version>1.5.6</version>
> 			<scope>test</scope>
> 		</dependency>
>
> I also added a GroovyTestCase file to src/test/java, and of course, it
> did not execute.
>
> I added the file to a src/test/groovy folder and it still did not  
> execute.
>
> Is the only way to get this to work by using the GMaven plugin?

It would definitely be easier.

--

LD.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org