Java/Scala的功能级行为测试工具

Ale*_*nov 5 java bdd scala

是否有与Cucumber/SpecFlow等效的Java或Scala ?一种可能性是使用带有JRuby的Cucumber; 还有别人吗?

Abh*_*kar 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)
    }
  }
}
Run Code Online (Sandbox Code Playgroud)


Eri*_*ric 6

specs为Literate规范提供了" 表单 ",以开发类似Fit的规范.你可以找到一个文章,解释它的基本原理在这里,和一些例子可以做什么.

但请注意,该库仍处于alpha模式,因为我计划在Scala 2.8.0解决后给予更多关注.