Richard Goh (5) [Avatar] Offline
#1
Hi Kostis,

I just tried Spock tests in chapter1 and I used Groovy/Grails Tool Suite with m2e plugin.

I managed to run 3 Spock tests with Maven test (Run As Maven test).

However, when I run chapter1 project as JUnit Test, the JUnit Rinner in GGTS only picked up Java unit tests and ignored Spock tests.

I also noticed the following error message in the project pom.xml file: Plugin execution not covered by lifecycle configuration: org.codehaus.gmaven:gmaven-plugin:1.4:compile (execution: default, phase: compile)

Is this the right behaviour or Spock tests are meant to run only in Maven test?

Thanks in advance.

- R.Goh
Kostis Kapelonis (55) [Avatar] Offline
#2
Hello R.Goh

The creator of Spock (Peter Niederwieser) works for Gradleware (makers of the gradle build system) and he seems to be an IntelliJ fan as well.
It is my feeling that the Spock + Gradle + IntelliJ combination gets more love than the Spock + Maven + Eclipse one (which is also the one I use) smilie

There is also a new version of Groovy 2.4.x that might break some things in Eclipse (Maven should work fine).
A new snapshot of Spock was released as well. I am currently evaluating the changes.

However I just checked my Eclipse installation and I can run all tests (Spock and JUnit) when I right-click on the project and select Run as -> JUnit test
Can you try to run each Spock test individually? Can you click for example on AdderSpec.groovy file and run it as JUnit? Does the file have the Groovy icon?

It is a bit hard to diagnose your Eclipse installation without some more details. The common trick that most people miss in Eclipse (and Spock) is that you have
to make sure that Spock tests are added as a source folder as well.

To do this
1)Right click on chapter 1 folder in the "Project Explorer" window and select properties
2)Choose the "Java build path" setting
3)Click the button "Add Folder..."
4)Make sure that src/test/groovy is also checked (and click on it if it is not)

In the next MEAP I will expand on the appendix chapter to give even more details about Spock installation and usage.

The second issue that you mention - Plugin execution not covered by lifecycle configuration: org.codehaus.gmaven:gmaven-plugin:1.4:compile (execution: default, phase: compile) is normal and expected. I have it as well but I don't see any side effect.

Kostis
Richard Goh (5) [Avatar] Offline
#3
Hi Kostis,

Many thanks for getting back.

It works after adding groovy to the source folder. However, it won't run for the first time as groovy code hasn't been compiled yet (ClassNotFoundException will be thrown for Spock test). To get the Spock tests working, I've to run the Maven test first then run the JUnit test again and the Spock tests work a treat.

Cheers
R.Goh