Num*Obj 在 Spock 中意味着什么
what does Num*Obj means in 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
}
首先,我建议不要使用以大写字母开头的变量名,尤其是当这些变量与实际 class 名称相同时 (!)。例如,我会更改
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" 了解更多信息。
假设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
}
首先,我建议不要使用以大写字母开头的变量名,尤其是当这些变量与实际 class 名称相同时 (!)。例如,我会更改
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" 了解更多信息。