I have a series of classes that extend from a base class. I've written spock tests classes for the classes with a base test class which tests normal functionality but in the case of a few classes the standard test logic does not work.
My plan was to simply override the base test methods when needed, but it appears that spock still runs them.
Example:
Base test:
def "testing name"() {
expect:
assert STANDARD CODE HERE
}
Subclass test:
def "testing name"() {
expect:
assert CUSTOM CODE HERE
}
But when I run the test, the base test's method is still running and failing.
As of Spock 0.7, overriding test methods in subclasses isn't supported, and you'll have to find a different way to structure your tests. For example, you could use the template method pattern, where a test method in the base class calls some abstract or concrete helper methods, which are then implemented or overridden in subclasses.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With