你如何使用 Scala 2.11 和 sbt 0.13 运行 黄瓜?

How do you run cucumber with Scala 2.11 and sbt 0.13?

有人有使用 sbt 0.13 和 Scala 2.11 的黄瓜项目示例吗?

  1. 我是否需要 cucumber-scala_2.11sbt-cucumber-plugin" % "0.8.0"(该插件是最新的)?
  2. 插件现在去哪儿了?
  3. .feature 文件去哪儿了?
  4. 黄瓜测试去了哪里?
  5. 如何 运行 来自 sbt 的测试?
  6. (可选)我怎样才能 运行 来自 IntellJ (15) 的测试?

好的,我找到了一个解决方案,但需要注意以下几点:我没有使用 sbt。

想法

我们先写黄瓜的特点和步骤。然后我们将编写一个“运行ner”class,它将是 JUnit 运行ner 的 运行(它将忽略黄瓜的存在)

程序

步骤 1。写黄瓜功能和步骤只靠一件事!

libraryDependencies += "info.cukes" % "cucumber-scala_2.11" % "1.2.4"

第 2 步:现在我们依赖于 junit(用于编写我们测试的 运行ner)和 cucumber-junit 连接库,这将使我们能够 告诉 JUni 运行 我们的黄瓜测试:

libraryDependencies += "info.cukes" % "cucumber-junit" % "1.2.4"
libraryDependencies += "junit" % "junit" % "4.12"

步骤 3:编写功能和步骤定义(根据我的经验,它们应该放在测试中的同一文件夹中):

# My.feature
Feature: blah blah
  ....

// MySteps.scala
...

第四步:编写我们的测试运行ner:

import cucumber.api.junit.Cucumber
import org.junit.runner.RunWith
@RunWith(classOf[Cucumber])
class RunTests extends {
}

步骤 5:(可选)与 IntelliJ 集成

a) 在 IntelliJ 中启用 JUnit。这将允许我们通过 运行ning 我们的 junit 运行ner 来 运行 我们的黄瓜测试。漂亮!

  1. 文件

  2. 设置...

  3. 插件

  4. 搜索“JUnit”并确保它已启用

    现在我们可以 运行 我们的黄瓜测试,只需右键单击 .feature 文件并选择 运行!

b) 启用 Cucumber for Scala IntelliJ 插件。 (确保 Scala 插件已启用)。这使 IntelliJ 能够确定如何将特征文件与 scala 文件相关联。如果没有这个,您的功能文件将始终以黄色突出显示并显示错误 undefined step reference:

  1. 文件

  2. 设置...

  3. 插件

  4. 浏览存储库...

  5. 搜索“Cucumber for Scala”

  6. 安装Cucumber for Scala插件

  7. 重启 IntelliJ。

    现在您的功能文件将正确突出显示!

有用的资源

  1. Java 黄瓜教程,这让我想到了这个解决方案:https://c0deattack.wordpress.com/2012/03/28/cucumber-jvm-with-cucumber-java-cucumber-junit-example/
  2. Cucumber 聊天室,人们超级乐于助人:https://gitter.im/cucumber/chat
  3. 目录结构(请注意,在 scala 中,我们似乎需要将功能文件和步骤文件放在同一个文件夹中:但是个人 运行ners 的想法很有趣):http://www.hascode.com/2014/12/bdd-testing-with-cucumber-java-and-junit/#Directory_Structure

添加到@drozzy 的答案,特别是 sbt: 在您的 sbt 项目中添加 junit-interface 作为依赖项

"com.novocode" % "junit-interface" % "0.11" % Test

按照@drozzy 在第 4 步中显示的那样编写测试 运行ner。 确保包含 JUnit 和 Cucumber 之间的连接:

@RunWith(classOf[Cucumber])

一旦您这样做,sbt test 将 运行 您的 JUnit 测试,并且您的 "JUnit tests" 之一将 运行 您的 Cucumber 测试。