concept @Shared annotation in category java
appears as: @Shared notation

This is an excerpt from Manning's book Java Testing with Spock.
You can indicate to Spock which objects you want to survive across all test methods by using the @Shared annotation. As an example, assume that you augment your electronic basket with a credit card processor:
![]()
Here you mark the expensive credit card processor with the @Shared annotation. This ensures that Spock creates it only once. On the other hand, the electronic basket itself is lightweight, and therefore it’s created multiple times (once for each test method). Notice also that the credit card processor is closed down once at the end of the test.