Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overridden spock test methods still running

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.

like image 751
Nathan Voxland Avatar asked Jan 10 '23 20:01

Nathan Voxland


1 Answers

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.

like image 182
Peter Niederwieser Avatar answered Jan 16 '23 18:01

Peter Niederwieser