spockframework / spockframework/spock
Cannot use stubbed methods in cleanup method if the test succeeds
Open
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 483
- PR merge metrics
- No merged PRs in 30d
Description
Issue description
I'm trying to use a stubbed method in a cleanup method. This works if an assertion failed in the test, but not if the test succeeds.
How to reproduce
class UseStubInCleanupSpec extends Specification {
def mock = Mock(java.util.function.Function)
def setup() {
mock.apply("a") >> { "b" }
}
def cleanup() {
assert mock.apply("a") == "b"
}
def "run a successful test"() {
expect:
true
}
def "run a failing test"() {
expect:
false
}
}
Java/JDK
1.8
Groovy version
2.3.10:indy
Operating System
Mac
IDE
IntelliJ
Gradle/Grails
compile 'org.spockframework:spock 1.0-groovy-2.3'
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 with the supplied UseStubInCleanupSpec reproducer and run both the successful and failing test methods on the stated Spock, Groovy, and JDK versions. Compare cleanup behavior in each case and trace the mock lifecycle; done means the stubbed method works during cleanup after a successful test without regressing the failing-test case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, java
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100