Num * Obj在Spock中是什么意思

时间:2019-06-11 00:35:12

标签: spock

让我们说deleteInvocation=1, notDeletedInvocation=2

这是否意味着我在输入数组之前在Post数组中有3条记录?

3 * postConverter.apply(Post, null) >> PostPayload

@Unroll
def "Verify PostCoreImpl.findById return  Post when includeRemoved: [#includeRemoved]"() {
    setup:
    def PostId = UUID.randomUUID()
    def Post = Mock(Post)
    def PostPayload = Mock(PostPayload)

    when:
    def actual = underTest.findPostById(PostId, includeRemoved, false, false)

    then:
    deleteInvocation * mockPostDataManager.findByIdincludeRemoved(PostId) >> Post
    notDeletedInvocation * mockPostDataManager.findById(PostId) >> Post
    3 * postConverter.apply(Post, null) >> PostPayload
    actual == PostPayload

    where:
    deleteInvocation | notDeletedInvocation | includeRemoved
    1                | 0                    | true
    0                | 1                    | false
}

1 个答案:

答案 0 :(得分:2)

首先,我建议不要使用以大写字母开头的变量名,尤其是当这些变量与实际的类名(!)相同时。例如,我会改变

def PostId = UUID.randomUUID()
def Post = Mock(Post)
def PostPayload = Mock(PostPayload)

def postId = UUID.randomUUID()
def post = Mock(Post)
def postPayload = Mock(PostPayload)

并更新所有使用这些变量的地方。


对于您的问题,在模拟或间谍对象上的符号integerNumber * methodCall(...)表示您想验证在测试(交互检查)期间methodCall(...)被正确地integerNumber次调用了。

请咨询Spock manual chapter "Interactions"以获得更多信息。

符号integerNumber * methodCall(...) >> stubResult表示您将互动与存根结合在一起,即使用模拟对象或间谍对象同时指定两件事。

请咨询Spock manual chapter "Combining Mocking and Stubbing"以获得更多信息。