Having trouble running a test within eclipse

1,382 views
Skip to first unread message

Hans Westerbeek

unread,
Oct 26, 2012, 10:06:33 AM10/26/12
to spockframework
Hi all,

I have used Spock for a long time now, and have always used it with
IntelliJ, which is fine.

Now I am introducing Spock to a team where people use eclipse, so I
must make sure people can just run the test within their IDE. I have
installed the latest version of STS, with all Groovy tools. My
project is built with Maven 3.0.4 and everything works beautifully in
my own Intellij. Also, surefire executes Specs properly when run from
the commandline.

We use eclipse:eclipse -DdownloadSources=true. (not m2eclipse) as per
http://code.google.com/p/spock/wiki/GettingStarted#Eclipse

Still, when i want to "run as => junit test" i am first greeted with a
dialogue "Problems launching JUnit Tests: The input type of the launch
configuration does not exist". Then, the launch config window pops
open and at the top displays: "Can not find test class 'FooSpec' in
project 'myproject''".

Any idea? I can obviously not get them on board otherwise :(

Cheers,
Hans

Peter Niederwieser

unread,
Oct 26, 2012, 10:10:43 AM10/26/12
to spockfr...@googlegroups.com
My best guess is that Groovy Eclipse is configured incorrectly, e.g. with the wrong Groovy version. The Eclipse log should tell you more.

Cheers,
Peter
> --
> You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
> To post to this group, send email to spockfr...@googlegroups.com.
> To unsubscribe from this group, send email to spockframewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/spockframework?hl=en.
>

Hans Westerbeek

unread,
Oct 26, 2012, 10:28:34 AM10/26/12
to spockfr...@googlegroups.com
Hmm I'll try... For the record i followed
http://mrhaki.blogspot.nl/2011/01/spocklight-add-spock-support-to-java.html

I have made some progress by changing the include-pattern for
src/test/groovy to .groovy, instead of the default .java that eclipse
was using. Now I get a CNF Exception. I noticed that eclipse puts the
.groovy file in target/test-classes, not a .class. The jUnit runner is
obviously assuming that it will find junit class in that location as a
.class.

See if I can fix that... Anyway it must be a matter of eclipse:eclipse
otherwise I won't be able to sell it...

Peter Niederwieser

unread,
Oct 26, 2012, 10:42:18 AM10/26/12
to spockfr...@googlegroups.com
`mvn eclipse:eclipse` isn't Groovy-aware, so you'll have to do some manual work. Probably your Groovy Eclipse is configured to put .groovy files into the output folder. The real problem is that it doesn't also put compiled classes there. That, in turn, probably means that it isn't able to compile the Groovy code. Again, have a look at the log view. Also, make sure you aren't compiling test code into target/classes.

Cheers,
Peter

Hans Westerbeek

unread,
Oct 27, 2012, 1:27:49 PM10/27/12
to spockfr...@googlegroups.com
The quest continues :)

I have the groovynature properly configured in the project, by adding
a bit of config to the maven-eclipse plugin:
<additionalProjectnatures>

<projectnature>org.eclipse.jdt.groovy.core.groovyNature</projectnature>
</additionalProjectnatures>

The problem has now been reduced to the groovy-eclipse compiler
barfing at an AST (i added @Slf4j). When I removed this, everything
works.
Apparently this is a know issue; http://jira.codehaus.org/browse/GRECLIPSE-1503

Cheers,
Hans

Peter Niederwieser

unread,
Oct 27, 2012, 1:38:15 PM10/27/12
to spockfr...@googlegroups.com
On Oct 27, 2012, at 7:27 PM, Hans Westerbeek <hanswes...@gmail.com> wrote:

> The problem has now been reduced to the groovy-eclipse compiler
> barfing at an AST (i added @Slf4j). When I removed this, everything
> works.
> Apparently this is a know issue; http://jira.codehaus.org/browse/GRECLIPSE-1503

Doesn't sound like a Spock-related problem. Can you tell us what exactly the problem was with the missing .class files? Maybe this will help other Maven users who are struggling to set up a Groovy project in Eclipse.

Cheers,
Peter

Hans Westerbeek

unread,
Oct 27, 2012, 2:11:34 PM10/27/12
to spockfr...@googlegroups.com
Indeed it is not spock-related. Let me finish up on my solution and
when the dust has settled, i will post my findings here for posterity
:)

Hans Westerbeek

unread,
Oct 29, 2012, 6:39:11 AM10/29/12
to spockfr...@googlegroups.com
I ended up with the following solution to be able to run spock tests
in a maven project, in eclipse, but without m2e or m2eclipse.

-1. use the latest version of the groovy eclipse plugin
-2. configure the maven eclipse pluging as follows: (note the
<sourceInclude> and the groovy nature)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<wtpversion>2.0</wtpversion>
<additionalConfig>
<file>
<name>.settings/org.eclipse.core.resources.prefs</name>
<content>

<![CDATA[eclipse.preferences.version=1${line.separator}encoding/<project>=${project.build.sourceEncoding}${line.separator}]]>
</content>
</file>
</additionalConfig>
<additionalProjectnatures>

<projectnature>org.eclipse.jdt.groovy.core.groovyNature</projectnature>
</additionalProjectnatures>
<downloadJavadocs>true</downloadJavadocs>
<downloadSources>true</downloadSources>
<sourceIncludes>
<sourceInclude>**/*.groovy</sourceInclude>
</sourceIncludes>
</configuration>
</plugin>

3: run maven eclipse:clean eclipse:eclipse and all should work.


Cheers,
Hans
Reply all
Reply to author
Forward
0 new messages