Groovy and Abstract superclass & mocking

1,589 views
Skip to first unread message

Murray Carr

unread,
Jun 25, 2012, 11:46:39 AM6/25/12
to spock
Hello,
Groovy 1.7.9

I am trying to mock out a method on an abstract super class of the class under test.
How would I go about doing this.  I have tried using metaClass so far to no avail.  
The class under test is a regular Java class not a groovy one if that makes it even harder.
cheers.
Muz

Peter Niederwieser

unread,
Jun 25, 2012, 6:14:11 PM6/25/12
to spockfr...@googlegroups.com
There are a couple of options:

* Refactor the code so that the code under test is in a separate class from the code to be mocked
* Subclass the class under test and mock out the method manually
* Use a mocking framework (like Mockito) that supports partial mocking

Cheers,
Peter

Murray Carr

unread,
Jun 25, 2012, 6:50:13 PM6/25/12
to spockfr...@googlegroups.com
I will look to subclassing tomorrow, I managed to make some progress with cglib to get over the initial problem.
Thanks for the tips Peter.
cheers.
muz

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To view this discussion on the web visit https://groups.google.com/d/msg/spockframework/-/1YK58_0wbIAJ.
To post to this group, send email to spockfr...@googlegroups.com.
To unsubscribe from this group, send email to spockframewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/spockframework?hl=en.

Reply all
Reply to author
Forward
0 new messages