8.1. Using additional Spock features for enterprise tests

Chapter 4 covered all Spock blocks in detail as well as the general structure of a Spock test. Spock offers several complementary features in the form of annotations that further enhance the expressiveness of your tests.

The Spock tests demonstrated here are based on the e-shop example introduced in chapter 6. They revolve around placing products in an electronic basket and paying via credit card.

8.1.1. Testing the (non)existence of exceptions: thrown() and notThrown()

In all Spock tests that I’ve shown you so far, the expected result is either a set of assertions or the verification of object interactions. But in some cases, the “expected” result is throwing an exception. If you’re developing ...

Get Java Testing with Spock now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.