Search code examples
mavenspock

Mocking of concrete class failing with Spock 2.0


Mocking of external concrete class fails with the below mentioned error.

java.lang.AbstractMethodError: Receiver class me.spike.LibraryTest does not define or inherit an implementation of the resolved method 'abstract java.lang.Object getProperty(java.lang.String)' of interface groovy.lang.GroovyObject.

I've tried adding cglibs-nodep and objenesis but was not successful in getting to mock the concrete class.

The repository mentioned here has a failing test. The test itself nonsensical. The intent is to get the mock working.

MCVE - https://github.com/ajaydivakaran/spock_spike


Solution

  • Like I said in the other question, you should get rid of the Build Helper plugin because Maven will recognise your src/test/groovy automatically - at least, as long as your src/test/java is not completely empty. Moreover, the Surefire plugin is over-specified, like I also told you before. You should keep your build files small and only include what is needed.

    But the real problem is that your Groovy Eclipse batch compiler is version 3.0.3 while you use Groovy version 2.5.11. Just downgrade that one dependency to fit your Groovy version, and your test runs normally. Or go the other way, upgrade Groovy and Spock to 3.0. Anyway, changing this line fixes your build:

    <groovy-eclipse-batch.version>2.5.11-01</groovy-eclipse-batch.version>