spockframework / spockframework/spock
Unable to have setup() in both class and trait without spock-junit4 module
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 483
- PR merge metrics
- No merged PRs in 30d
Description
Issue description
Spock 2.0-M3 removed native support for @Before/@After/... annotations from JUnit 4. As a result it is no longer possible to use them without the spock-junit4 module. Unfortunately the same type of a fixture method (e.g. setup()) cannot be used simultaneously in the tests specification and a trait.
How to reproduce
class Legacy142InegrationTest extends Specification implements TimeResetGuardian {
def cleanup() {
//some spec specific cleanup
}
...
}
trait TimeResetGuardian {
def cleanup() {
//resets global time variable to "now" in poorly written legacy integration tests
}
}
Additional comment
Calling cleanup() from a specification class is not permitted in Spock. The method in a trait could have some other name, but it would be error-prone to (in addition) require to call it from the cleanup method in the specification.
This is one of the cases where is might be useful to do some generic setup/cleanup in traits. Maybe we could have some alternative mechanism for the fixture methods?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the reproduced Specification and TimeResetGuardian trait, then trace how Spock discovers and rejects fixture methods with the same name. The issue does not name implementation files or tests; done would require a defined mechanism that supports generic trait setup or cleanup without requiring spock-junit4 or an error-prone manual call.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, java
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100