0
votes

I'm new to the Spock framework, and I have an issue with using an abstract java test class with it.

What I would like to have is a groovy test class, which extends some other java abstract class with some common methods, which in turn extends Specification class.

So, the code is as follows:

class GroovyTest extends AbstractTest {
    def "my test"() {
        ....
    }
}

public abstract class AbstractTest extends Specification {
    ...
    some common methods
    ...
}

When I ran the GroovyTest class I'm getting the following error:

org.spockframework.runtime.InvalidSpecException: Specification 'org.my.package.AbstractTest' was not compiled properly (Spock AST transform was not run); try to do a clean build

When I'm using a groovy abstract class then it works without errors.

So my question is there a way to use Java class with Spock framework?

1
Why would you do that? You would get no benefit that I can think of by building this sort of tower of Babel, so I'm interested to understand the problem you're trying to solve - tim_yates
I just has an abstract java class with common methods, that are used among different java tests. Now I'm trying to add new tests written in Groovy, but I also need functionality from this class. Thats the reason I don't want it to change to be a groovy class. - androberz
How do you want to reuse this abstract Java class? Do you want to extend Java test from Spock specification? - Cortwave
I'm just wondering about possibility to extend Spock specification by the Java test class, particularly it's not prohibited by compiler. - androberz

1 Answers

2
votes

Spock is a DSL Groovy based testing language. It executes transformations (AST) to canonical Groovy code before test execution. In your case you try to write Java-based Spock test. Spock can't execute AST transformations from canonical Java code and throws IvalidSpecException.