Spock framework: how can I automatically reset object state after spec is completed

1.8k views Asked by At

I've got Spring service A which internally uses service B.

I want:

  1. Mock service B
  2. Set mocked version into service A
  3. Test service A behavior
  4. Set previous version of service B to service A (reset state)

The problem is last step - I can remember B at setup and set it in cleanup stages. But can I configure to do it automatically (something similar to @ConfineMetaClassChanges)

1

There are 1 answers

0
Peter Niederwieser On

This isn't supported out-of-the-box, but it could be implemented as a JUnit rule or Spock extension. (@ConfineMetaClassChanges is a Spock extension.)