How to Run a Spock Test inside Eclipse
Asked Answered
F

3

14

I try to run my first Spock Test inside Eclipse, and it does not work.

I added all the Maven dependencies and plugins in my pom.xml, but when I run my test with jUnit, there is a popup windows with this Warning message : "No jUnit tests found".

Did you already seen this kind of message ?

What config has to be done, in order to run a Spock Test inside Eclipse ?

Thanks a lot.

Fluorosis answered 2/5, 2012 at 13:52 Comment(3)
I assume you've followed these steps?Sonni
YEs : Verified against Eclipse 3.6, 3.7 Install the Groovy Eclipse Plugin : Done Enable the following option: Done For Eclipse 3.5 and below : I use Eclipse Indigo with Maven Create a new Java project : this is an existing project Download spock-core-0.6-groovy-1.8.jar : I have got it my dependencies Add JUnit 4 (4.7 or higher) : coming from the spock-core dependency In the src folder, create a Groovy class named HelloSpock with the following content: HelloSpock.groovy : DONe In Project Explorer, right-click HelloSpock and select Run As -> JUnit Test : DOes not workFluorosis
I have the same problem. All spock-core, groovy-all and junit are in the maven dependencies. Have you found the solution?Shaggy
A
2

Its same as running Junit test cases. Right click on the class and run as 4Junit Test runner. see below for complete configurations and running the spock test.

Running Spock Framework with Eclipse, Gradle, Groovy: Source - Krzysztof Goralski, blog

-Install Gradle Plugin, check it here

-Install Groovy-Eclipse for Juno or Indigo from Eclipse Marketplace (or maybe Groovy/Grails Tool Suite for Eclipse)

-Install Spock Plugin From Eclipse Marketplace if you want, check it here

-Import Project to Eclipse through Gradle Import

-Add these lines to build.gradle:

apply plugin: ‘groovy’
testCompile ‘org.spockframework:spock-spring:1.0-groovy-2.3’ (for Spring)

this is quite important, version can make some conflicts

-After this *.groovy and *.gradle files will problably looks different, Syntax colour highlightning etc. Remember that you can right click on for eg. build.gradle -> Open with -> Open With Minimalist gradle Editor etc.

-Probably you will need to make additional folder for *.groovy test files Create new *.groovy file, class

-Basic test example, extends Specification from Spock framework and needs specific Annotations when running with Spring

-Now you can run it with JUnit from Eclipse For integration tests you can’t use @RunWith(SpringJUnit4ClassRunner.class), and Context should looks like here @ContextConfiguration(locations = [ “/restTestContext.xml” ]) , not {} braces, but [ ]

-Spock can be used for Mocks too. Something like this: Subscriber subscriber1 = Mock() , subscriber1.isActive() >> true , So, remember >> operator for mocks.

Alcalde answered 16/5, 2017 at 11:54 Comment(0)
S
1

Right click on the project > Properties > Java Build Bath > Add External Jars and add spock-core-0.6-groovy-1.8.jar and check if Groovy Libraries are there in Build Path or not. If not click on Add Library and select Groovy Runtime Libraries and restart Eclipse. Now you should be able to run. If still can't Run then try creating New Configuration and change the Test runner to Junit4 and Run it...

Sales answered 15/5, 2012 at 15:25 Comment(0)
T
0

Check if the folder your tests are in is a source folder.

Timorous answered 26/7, 2013 at 14:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.