Monday, 15 September 2014

How to write spock tests for a service in grails? -



How to write spock tests for a service in grails? -

i have grails application service called mysampleservice.groovy in grails-app/services/com/myapp/

the service has method:

boolean spocktest() { homecoming false; }

i've added in buildconfig.groovy

test(":spock:0.7") { exclude "spock-grails-support" }

question

how/where should write spock test service? how run it?

a simple service:

// grails-app/services/com/myapp/mysampleservice.groovy bundle com.myapp class mysampleservice { def somemethod(string arg) { arg?.touppercase() } }

a spock spec service:

// test/unit/com/myapp/mysampleservicespec.groovy bundle com.myapp import grails.test.mixin.testfor import spock.lang.specification @testfor(mysampleservice) class mysampleservicespec extends specification { void "test somemethod"() { expect: service.somemethod(null) == null service.somemethod('thin lizzy') == 'thin lizzy' } }

you can run test grails test-app unit:.

you didn't mention version of grails using. 2.4.0 won't need create mention of spock in buildconfig.groovy in order work.

grails spock

No comments:

Post a Comment