1

我最近开始在我的 Java 项目中使用用于 BDD的spock 框架。我注意到在 spock 规范中,可以在规范中定义一个特性和一个 given-when-then 子句。例如:

MySpec extends Specification {

  //As a User I want the system to behave in some way

  def "it should provide feature 1"() {
    given: "some state"
    when : "some action"
    then : "some symptom"
  }

  def "it should provide feature 2"() {
    ...
  }
}

我缺少的是规范的用户故事部分,即我在评论中添加的部分。

是否可以以某种方式编写一个 spock 规范,以提供以下格式的测试输出:

+As a User I want the system to behave in some way
  +it should provide feature 1
    -given some state
    -when some action
    -then some symptom
  +it should provide feature 2
    -given some state
    -when some action
    -then some symptom

这与ScalaTest输出结果的方式非常相似。

我基本上缺少可以让我轻松分组和显示功能的顶级元素。我想知道是否有这样的构造,或者我是否不了解 spock 框架的真实性质。

4

1 回答 1

3

正在为 Spock 1.0 制作的新业务报告将通过@Narrative附加到规范类的注释来支持此功能。要获得第一印象,请参阅此示例规范生成的报告

于 2013-05-08T22:17:22.043 回答