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)
}
}
}
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)
}
}
}
specs provides Literate Specifications with "forms" to develop Fit-like specifications. You can find a post explaining the rationale of it here, and some examples of what can be done with it.
Note however that the library is still in alpha mode as I plan to give it more attention once Scala 2.8.0 has settled.
JBehave works just fine with Scala. For an example, in this article, http://jnb.ociweb.com/jnb/jnbJun2010.html there is a link to a zip file that contains a sample application using JBehave implemented completely in Scala.
Look at Fitness, if you want to separate test code from acceptance text. Otherwise, both Specs and ScalaTest support BDD-style (Specs was written to be BDD-style), and lots of other Java frameworks support it was well.
JBehave was rewritten after Cucumber was released, so that we could also use plain text. Gherkin wasn't out when we wrote it, so it doesn't parse exactly the same - uses tokens instead of regexp - but it'll do the same job.
发布评论
评论(6)
查看具有功能规范的 ScalaTest。 ScalaTest 网站的示例功能规范:
Take a look at ScalaTest with Feature Spec. Sample feature spec from the ScalaTest website:
规范 通过“forms" 来开发类似 Fit 的规范。您可以在此处找到解释其基本原理的帖子< /a> 以及一些示例 使用 ="http://specs.googlecode.com/svn/samples/LiterateSpecifications/org.specs.samples.bagFormSpec.html" rel="nofollow noreferrer">它。
但请注意,该库仍处于 alpha 模式,因为我计划在 Scala 2.8.0 稳定后给予它更多关注。
specs provides Literate Specifications with "forms" to develop Fit-like specifications. You can find a post explaining the rationale of it here, and some examples of what can be done with it.
Note however that the library is still in alpha mode as I plan to give it more attention once Scala 2.8.0 has settled.
现在您可以使用 Cucumber 并在 Java 或纯 Scala 中定义您的步骤。
这里有一个关于如何在 Scala 中通过 SBT 使用它的简短教程:http://func.io/post/36452127031/pure-scala-bdd-made-easy-with-sbt-and-cucumber。
Now you can use Cucumber and define your steps in Java or pure Scala.
Here you have a short and easy tutorial on how to use it in Scala with SBT: http://func.io/post/36452127031/pure-scala-bdd-made-easy-with-sbt-and-cucumber.
JBehave 与 Scala 配合得很好。例如,在本文中,http://jnb.ociweb.com/jnb/jnbJun2010。在 web.html 中,有一个 zip 文件的链接,其中包含一个使用 JBehave 完全在 Scala 中实现的示例应用程序。
直接链接到 zip: http://www.ociweb.com/jnb/jnbJun2010 -scala-保龄球.zip
JBehave works just fine with Scala. For an example, in this article, http://jnb.ociweb.com/jnb/jnbJun2010.html there is a link to a zip file that contains a sample application using JBehave implemented completely in Scala.
Direct link to zip: http://www.ociweb.com/jnb/jnbJun2010-scala-bowling.zip
如果您想将测试代码与接受文本分开,请查看 Fitness。否则,规范和ScalaTest 支持 BDD 风格(Specs 被编写为 BDD 风格),并且许多其他 Java 框架都很好地支持它。
Look at Fitness, if you want to separate test code from acceptance text. Otherwise, both Specs and ScalaTest support BDD-style (Specs was written to be BDD-style), and lots of other Java frameworks support it was well.
JBehave在Cucumber发布后进行了重写,使得我们也可以使用纯文本。当我们编写它时,Gherkin 还没有出来,所以它的解析方式并不完全相同——使用标记而不是正则表达式——但它会做同样的工作。
http://jbehave.org
JBehave was rewritten after Cucumber was released, so that we could also use plain text. Gherkin wasn't out when we wrote it, so it doesn't parse exactly the same - uses tokens instead of regexp - but it'll do the same job.
http://jbehave.org