小编Tam*_*más的帖子

Spock特征方法的前提条件有什么好的风格?

在特征方法中,指定when:块中的特征动作,其结果在后续then:块中进行测试.通常需要准备,这在一个given:条款(setup:或夹具方法)中完成.包含前提条件同样有用:这些条件不是特征测试的主题(因此不应该在when:- then:expect:),但它们断言/记录测试有意义的必要条件.例如,参见下面的虚拟规范:

import spock.lang.*

class DummySpec extends Specification {
  def "The leading three-caracter substring can be extracted from a string"() {
    given: "A string which is at least three characters long"
    def testString = "Hello, World"

    assert testString.size() > 2

    when: "Applying the appropriate [0..2] operation"
    def result = testString[0..2]

    then: "The result is three characters long"
    result.size() == 3
  }
}
Run Code Online (Sandbox Code Playgroud)

这些先决条件的建议做法是什么?我assert在示例中使用了但很多人对assert规范中的s …

spock

7
推荐指数
1
解决办法
998
查看次数

标签 统计

spock ×1