Java Reference
In-Depth Information
The idea is that even if the mock is configured to throw an exception, the tribble test still
passes. The test verifies that the exception is thrown without making the test itself fail.
6.4.5. Other Spock capabilities
The capabilities shown so far hopefully provide a teaser for Spock. There are more features
in Spock that go beyond the scope of this chapter. For example, the @Ignore annotation
on a test skips that test, but there's also an @IgnoreRest annotation that skips all the
other tests instead. The @IgnoreIf annotation checks a Boolean condition and skips the
test if the condition evaluates to true. There's also a @Stepwise annotation for tests that
have to be executed in a particular order, and a @Timeout annotation for tests that are
taking too long to execute.
Lessons learned (Spock)
1 . Spock tests extend spock.lang.Specification
2 . The Specification class has a JUnit runner, so Spock tests run in your exist-
ing JUnit infrastructure.
3 . Spock test names are descriptive sentences. The framework uses AST transforma-
tions to convert them to legal Groovy.
4 . The tests are composed of blocks, like expect or when/then . Expressions in
an expect or then block are evaluated for the Groovy Truth automatically.
5 . The old method from spock.lang.Specification evaluates its argument
before the when block is executed.
6 . The where block is used to iterate over test data, either from a table, a database
result, or any data structure over which Groovy can iterate.
7 . Spock has its own built-in mocking capabilities.
ThewikiforSpockcontainsmanyexamples,aswellasdetaileddocumentationaboutmock
details (called interactions ) and more. The source code also comes with a Spock example
Search WWH ::




Custom Search