Skip to content

Instantly share code, notes, and snippets.

@andrezrv
Last active December 24, 2015 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrezrv/6717784 to your computer and use it in GitHub Desktop.
Save andrezrv/6717784 to your computer and use it in GitHub Desktop.
How to test with Spock using Build Test Data Plugin for Grails. Spock Docs: http://docs.spockframework.org/ Build Test Data Docs & Repo: https://github.com/tednaleid/build-test-data
package myapp.downloads
import grails.test.mixin.TestFor
import spock.lang.Specification
import grails.buildtestdata.mixin.Build
/**
* See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage instructions
*/
@TestFor( Download )
@Build( [ Download ] )
class DownloadSpec extends Specification {
void "test Download.getFullName() method"() {
// Create some objects to test with.
def download = Download.build()
given: "Try to get full name for the person associated to the download"
def result = download.getFullName()
when: "Returned value equals the concatenation of name and lastname"
download.person.name + ' ' + download.person.lastName == result
then: "Print success message"
println( '# SUCCESS: Test for Download.getFullName() passed.' )
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment