spockframework / spock

The Enterprise-ready testing and specification framework.
https://spockframework.org
Apache License 2.0
3.54k stars 466 forks source link

Cannot use stubbed methods in cleanup method if the test succeeds #616

Open prismec opened 8 years ago

prismec commented 8 years ago

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'
leonard84 commented 8 years ago

What would be the usecase for this?

prismec commented 8 years ago

The usecase is that the component under test should be shutdown during cleanup but a component that is referenced by the component under test is stubbed and used during shutdown.

JetyCZ commented 7 years ago

I would wish that stubbed methods work in cleanup too.

My usecase is, that in cleanup of all my test extending my AbstractMockMvcControllerTest, I render HTML output of the tested controller (which helps me to visually check if view was rendered ok during development). Controller is tested using MockMvc Spring class.