Java Reference
In-Depth Information
mavenCentral()
}
dependencies {
groovy "org.codehaus.groovy:groovy-all:2.1.5
testCompile "org.spockframework:spock-core:0.7-groovy-2.0"
}
The repository at Maven central holds the Groovy distribution and the Spock release
versions. The dependency is decoded in the usual way, with the group being
“org.spockframework,” the name (or artifact ID, in Maven speak) being “spock-core,” and
the version number of 0.7-groovy-2.0. Note that the Spock version is tied to a Groovy ver-
sion.
6.4.2. Test well, and prosper
Spock tests all extend a superclass called
spock.lang.Specification
. In addition
to its own methods, the
Specification
class includes the
@RunWith
annotation from
JUnit. The result is that Spock tests can be run within the normal JUnit testing infrastruc-
ture.
The tests themselves all have a common form. Each test method (known as a
fixture
) is de-
clared using the
def
keyword, followed by a string that describes what the test is supposed
to accomplish. Fixture methods normally take no arguments.
Spock tests easily identifiable, especially when your system uses both Spock and JUnit
tests together.
20
Spock tests in Grails
do
have to end in
Spec
.
Listing 6.26. A specification verifying basic
java.lang.String
behavior
import
spock.lang.Specification;
class
StringSpec
extends
Specification {
String llap
def
setup() { llap = "Live Long and Prosper" }