Chapter 7 shows how to use the Groovy SQL package to preload your database with test data needed for the Spock test. If you like this approach, you can take it a step further with the Spock dbUnit extension (https://github.com/janbols/spock-dbunit).
The extension is based on the well-known DbUnit library (http://dbunit.sourceforge.net/), initially developed for JUnit, that can initialize a database to a known state, reading data from XML files. The Spock dbUnit extension allows you to use Groovy code instead of XML files, as shown in the following listing.
Data on the DB is saved via a data source, which can be created by hand, or—even better—injected by Spring test, as shown in the next listing.
At the time of writing, this Spock extension is only in JCenter (https://bintray.com/bintray/jcenter), not Maven Central, so you must either build it yourself or configure JCenter in your pom.xml.
18.188.151.107