【发布时间】:2020-07-02 23:28:10
【问题描述】:
我正在尝试编写一个简单的测试,我想用一些运行时变量来验证模拟调用。目前它看起来像这样:
class Spec extends Specification implements SampleData {
EventBus eventBus = Mock()
Facade facade = new Configuration().facade(eventBus)
def "when the method is called an proper event is emitted"() {
when:
def id = facade.call(sampleData)
then:
1 * eventBus.push(_ as Event)
}
}
但我想要实现的也是验证事件的有效负载是否正确 - 这意味着事件包含id,如下所示:
then:
1 * eventBus.push(new Event(id))
有没有可能在 Spock 中实现这样的验证?
【问题讨论】:
标签: java unit-testing testing spock