Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
给定下面的 spock 测试,该setup块为块中的每个数据元素运行一次where。我可以让它只运行一次吗?
setup
where
setup: def x = 1 when: x++ then: x == y where: y << [2, 3, 4]
只需使用 @Shared 注释并将x声明为类字段。该值将在功能方法执行之间(也可以在多个功能方法之间)重用。
class SomeSpockSpec extends Specification { @Shared def x = 1 def 'x going to be incremented'() { when: x++ then: x == y where: y << [2, 3, 4] } }