Java Reference
In-Depth Information
Listing 7.5. The Gradle build file for the account application
apply plugin:'groovy'
apply plugin:'eclipse'
repositories {
mavenCentral()
}
def springVersion = '3.2.2.RELEASE'
def spockVersion = '0.7-groovy-2.0'
dependencies {
compile "org.codehaus.groovy:groovy-all:2.1.5"
compile "org.springframework:spring-context:$springVersion"
compile "org.springframework:spring-jdbc:$springVersion"
runtime "com.h2database:h2:1.3.172"
runtime "cglib:cglib:2.2"
testCompile "org.springframework:spring-test:$springVersion"
testCompile "org.spockframework:spock-core:$spockVersion"
testCompile "org.spockframework:spock-spring:$spockVersion"
}
Thebuildfile istypical ofprojects presented inthisbooksofar.Itdeclares boththeGroovy
and Eclipse plugins. It uses Maven central for the repository. The dependencies include
Groovy and Spock, as usual. Spring is added by declaring the
spring-context
and
spring-jdbc
dependencies. Those dependencies wind up adding several other Spring-
related JARs. The
h2database
dependency is used for the H2 driver needed by the em-
bedded database.
One interesting addition is the
spock-spring
dependency. Spring includes a powerful
testing framework of its own, which is based on JUnit and automatically caches the Spring
application context. The
spock-spring
dependency lets Spock tests work with the
Spring testing context.
The first test class is a Spock test for the
JdbcAccountDAO
. The following listing shows
some of the tests from the complete set.
Listing 7.6. Spock tests for the
JdbcAccountDAO
implementation
import spock.lang.Specification;
@ContextConfiguration("classpath:applicationContext.xml")
@Transactional