
spock - issue #282
Junit After/AfterClass/Before/BeforeClass methods from superclass should not be called if they have been overrided in the derived class
Spock calls all After/AfterClass/Before/BeforeClass methods from derived and base class and thus a overridden method gets called twice.
Junit After/AfterClass/Before/BeforeClass javadoc has been clarified in this commit: https://github.com/KentBeck/junit/commit/d48bf9735b916e7f2c06575970f90dff6f512822 It's also explained well in this junit issue: https://github.com/KentBeck/junit/issues/394
The new javadoc now contains this information: "The AfterClass methods declared in superclasses will be run after those of the current class, unless they are shadowed in the current class."
This logic is missing from Spock.
I'll attach the test case and fix as a github pull request.
Comment #1
Posted on Nov 19, 2012 by Happy BearPull request with fix and unit test: https://github.com/spockframework/spock/pull/10
Comment #2
Posted on Nov 19, 2012 by Happy Bearthis fix should make Spock behave like Junit does
Comment #3
Posted on Nov 19, 2012 by Happy BearTypical use case of superclass with duplicate Before*/After* methods in Grails: http://jira.grails.org/browse/GRAILS-9480 . It contains a test app that reproduces the problem in a Grails app . The pull request also contains a proper unit test case.
Comment #4
Posted on Dec 4, 2012 by Grumpy CatThanks a lot for making us aware of the changed JUnit behavior. I've taken this as an opportunity to add direct support for JUnit annotations, and direct support for multiple fixture methods per class.
Status: Fixed
Labels:
Type-Defect
Module-Core
Milestone-1.0