這個篇章再介紹點常用的用於spock的裝飾器
一、Rollup & Unroll
從字面意思來理解,就是捲起 & 展開,所以我們就很好理解這兩個註釋是什麼意思了,主要是用在多參數的用例中,我們來用例子實踐一下,還是之前文章的例子
def "maximum of #a & #b to numbers should #c"(){ when: def sum = Math.max(a, b) def result = c then: sum == result where: a|b|c 1|3|3 7|4|7 0|0|0 } @Rollup def "maximum of rollup test"(){ when: def sum = Math.max(a, b) def result = c then: sum == result where: a|b|c 1|3|3 7|4|7 0|0|0 }
這有兩個例子,一個是加了rollup的。結果會是怎麼樣呢?運行後結果如下:
可以看到, 加了@Rollup的用例會將參數化用例顯示爲一條。要注意的是:現在默認都是unroll了,所有用例中可以不用特別加@Unroll
二、Ignore
用例的跳過,相信大家在用不同框架都會遇到,實例說明下:
@Ignore def "test_ignore"(){ expect: 1==1 }
@IgnoreIf({System.getProperty("os.name").toLowerCase().contains("windows")}) def "test_ignore_if"(){ expect: 1==1 }
不運行
除了上面3個,還有一些內置關鍵字,比如:@Requires @PendingFeature @Stepwise @Timeout @Retry @Use 等等,如果有需要的可以點擊連接查看官網。
三、併發
並想根據spock 併發文檔試着做一下:https://spockframework.org/spock/docs/2.0/all_in_one.html#parallel-execution
結果沒成功。試着去查了下,很多還是沒解決。棄之.............