Spock Framework: problems with spying

放肆的年华 提交于 2019-12-01 08:24:17

It should be:

@Grab('org.spockframework:spock-core:0.7-groovy-2.0')
@Grab('cglib:cglib-nodep:3.1')

import spock.lang.*

class CallingClassTest extends Specification {

    def "check that functionTwo calls functionOne"() {
        def c = Spy(CallingClass)

        when:
        def s = c.functionTwo()

        then:
        1 * c.functionOne() >> "mocked function return"
        s == "some string mocked function return"
    }
}

public class CallingClass {

    public String functionOne() {
        "one"
    }

    public String functionTwo() {
        String one = functionOne()        
        "some string $one"
    }
}

When you both spy/mock and verify this is how return value should be specified.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!