Spock as Testing framework - requires Specification Superclass

Hi,

i’ve a question regarding the increasingly famous testing framework spock. I added it into my gradle dependencies and it worked fine for unit tests.

Unfortunately it requires me to extend from “spock.lang.Specification”. For middleware integration tests CUBA as well requires me to extend from TestContainer (like described in the docs: Middleware Integration Tests - CUBA Platform. Developer’s Manual).

This is a pitty. Does anyone have a glue on what to do? Should i copy the content of your TestContainer implementation and let this one extend from Specification or something? I could probably hack way around that, but i would be interested in your thoughts on that one…

Bye,
Mario

Hi Mario,
The platform middleware tests classes do not have to extend anything. TestContainer and its subclass in the project are used as a @ClassRule. Are you sure it is incompatible with Spock?

Hi Konstantin,

you are right. I think i totally missed the point. I just overlooked the fact that SalesTestContainer in the docs is just meant as a “Helper” class - and thought that was the actual test.

So then, obviously it’s no problem. Spock has an integration with JUnit Rules and ClassRules like described here: JUnit Rules and Spock · JVM. Blog.

So, we can close this one. I’ll give it another try :slight_smile:

Thanks!

Bye,
Mario

Hi Mario,
can you better explain the process, if possible with a little example, by which you succeded in this integration?

Thanks,
Fabrizio

Hi,

We are using such Spock setup right in the framework: see JpaCascadeTest.groovy as the example.

Essential part is:

class JpaCascadeTest extends Specification {

    @Shared @ClassRule
    public TestContainer cont = TestContainer.Common.INSTANCE

Thank you very much
Fabrizio