"given" 这个词有什么用吗?

Does the "given" word serve any purpose?

据我所知,表达式 given:(开始 "given" 块)在 Spock 测试中什么都不做,如果您忽略它,它们的功能完全相同。

有谁知道有什么不同吗?

来自 Spock documentation,

The given block is where you do any setup work for the feature that you are describing. It may not be preceded by other blocks, and may not be repeated. A given block doesn’t have any special semantics. The given: label is optional and may be omitted, resulting in an implicit given block. Originally, the alias setup: was the preferred block name, but using given: often leads to a more readable feature method description (see Specifications as Documentation).

所以,最终是的,如果你省略它,它的功能是一样的,因为 Spock 无论如何都会隐式地将标签放在那里;但是明确显示 given 标签有助于记录您的测试。