spockframework / spockframework/spock

Cannot use stubbed methods in cleanup method if the test succeeds

Open
#616 7 comments 1 reaction 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.