Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Run a Spock Test inside Eclipse

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.

like image 385
Gillespie59 Avatar asked May 02 '12 13:05

Gillespie59


1 Answers

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.

like image 200
smali Avatar answered Sep 24 '22 19:09

smali