Java/Scala特性级行为测试工具

5

是否有Java或Scala等价于Cucumber/SpecFlow的工具?其中一种可能是使用JRuby与Cucumber;还有其他选择吗?


1
也许这个链接https://dev59.com/qnNA5IYBdhLWcg3wKacx会有所帮助。 - Mark
1
你有看过现有的框架吗?就Scala而言,ScalaTest支持BDD,而Specs则是专为BDD设计的。此外,还有许多Java的测试框架可供选择。也许如果您能更好地解释您的要求,那么回答这个问题会更容易些。 - Daniel C. Sobral
6个回答

8

请查看使用Feature Spec的ScalaTest。以下是来自ScalaTest网站的样本特性规范:

import org.scalatest.FeatureSpec
import org.scalatest.GivenWhenThen
import scala.collection.mutable.Stack

class ExampleSpec extends FeatureSpec with GivenWhenThen {

  feature("The user can pop an element off the top of the stack") {

    info("As a programmer")
    info("I want to be able to pop items off the stack")
    info("So that I can get them in last-in-first-out order")

    scenario("pop is invoked on a non-empty stack") {

      given("a non-empty stack")
      val stack = new Stack[Int]
      stack.push(1)
      stack.push(2)
      val oldSize = stack.size

      when("when pop is invoked on the stack")
      val result = stack.pop()

      then("the most recently pushed element should be returned")
      assert(result === 2)

      and("the stack should have one less item than before")
      assert(stack.size === oldSize - 1)
    }

    scenario("pop is invoked on an empty stack") {

      given("an empty stack")
      val emptyStack = new Stack[String]

      when("when pop is invoked on the stack")
      then("NoSuchElementException should be thrown")
      intercept[NoSuchElementException] {
        emptyStack.pop()
      }

      and("the stack should still be empty")
      assert(emptyStack.isEmpty)
    }
  }
}

6

specs 提供了使用 "forms" 开发 Fit-like 规范的可读规范。你可以在这里找到解释其基本原理的文章,以及 一些示例 展示了 可以做什么如何使用

需要注意的是,该库目前仅处于 alpha 模式,我计划在 Scala 2.8.0 定型后再为其投入更多关注。


4

3

1
JBehave在Cucumber发布后进行了重写,以便我们也可以使用纯文本。当我们编写它时,Gherkin还没有出现,因此它的解析方式不完全相同-使用标记而不是正则表达式-但它可以完成相同的工作。

http://jbehave.org


1

如果你想将测试代码和验收文本分离,请看一下Fitness。否则,SpecsScalaTest都支持BDD风格(Specs是为BDD风格编写的),很多其他的Java框架也支持。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接