Mark Bramnik Mark Bramnik - 5 months ago 43
Java Question

What is the difference between Annotation Driven and Global extensions in Spock

I'm trying to learn about writing extensions in Spock testing framework.
I've come across 2 different types of extensions:

  • Annotation Driven (like
    , etc)

  • Global Extension (like for integrating spring framework inside the test)

So my question is:
What is the difference between them? When should I prefer one type of extensions over another for my custom extensions?



Annotation driven extensions have a smaller scope and usually only affect a single test method (or a group of methods)

Global extensions have a larger scope and allow you to affect how Spock does things in an broader area (e.g. reporting)

My suggestion would be for you to start with an annotation extension and see if you can accomplish what you want in the smallest scope possible.