Forgus / spock

Automatically exported from code.google.com/p/spock
0 stars 0 forks source link

Junit After/AfterClass/Before/BeforeClass methods from superclass should not be called if they have been overrided in the derived class #282

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
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/d48bf9735b916e7f2c06575970f90dff6f51282
2
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.

Original issue reported on code.google.com by lari.hot...@sagire.fi on 19 Nov 2012 at 11:48

GoogleCodeExporter commented 8 years ago
Pull request with fix and unit test: 
https://github.com/spockframework/spock/pull/10

Original comment by lari.hot...@sagire.fi on 19 Nov 2012 at 11:53

GoogleCodeExporter commented 8 years ago
this fix should make Spock behave like Junit does

Original comment by lari.hot...@sagire.fi on 19 Nov 2012 at 2:21

GoogleCodeExporter commented 8 years ago
Typical 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. 

Original comment by lari.hot...@sagire.fi on 19 Nov 2012 at 5:40

GoogleCodeExporter commented 8 years ago
Thanks 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.

Original comment by pnied...@gmail.com on 4 Dec 2012 at 1:02