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

发布于 2024-09-04 15:07:18 字数 185 浏览 2 评论 0 原文

是否有相当于 Cucumber/SpecFlow?一种可能性是将 Cucumber 与 JRuby 结合使用;还有其他人吗?

Is there a Java or Scala equivalent to Cucumber/SpecFlow? One possibility is using Cucumber with JRuby; any others?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

彻夜缠绵 2024-09-11 15:07:18

查看具有功能规范的 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)
    }
  }
}

Take a look at ScalaTest with Feature Spec. Sample feature spec from the ScalaTest website:

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)
    }
  }
}
听风念你 2024-09-11 15:07:18

规范 通过“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.

远昼 2024-09-11 15:07:18

现在您可以使用 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.

街角卖回忆 2024-09-11 15:07:18

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

冷夜 2024-09-11 15:07:18

如果您想将测试代码与接受文本分开,请查看 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.

も让我眼熟你 2024-09-11 15:07:18

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文