您如何使用 Scala 2.11 和 sbt 0.13 运行 cucumber? [英] How do you run cucumber with Scala 2.11 and sbt 0.13?

查看:34
本文介绍了您如何使用 Scala 2.11 和 sbt 0.13 运行 cucumber?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Does anyone have an example of a cucumber project with sbt 0.13 and Scala 2.11?

  1. 我是否需要 cucumber-scala_2.11sbt-cucumber-plugin" % "0.8.0"(该插件是最新的)?
  2. 插件现在去哪儿了?
  3. .feature 文件在哪里?
  4. 黄瓜测试去哪儿了?
  5. 如何从 sbt 运行测试?
  6. (可选)如何从 IntellJ (15) 运行测试?
  1. Do I need both the cucumber-scala_2.11 and the sbt-cucumber-plugin" % "0.8.0" (is that plugin up to date)?
  2. Where does the plugin go now?
  3. Where do the .feature files go?
  4. Where do the cucumber tests go?
  5. How do I run the tests from sbt?
  6. (optional) How can I run the tests from IntellJ (15)?

推荐答案

好的,我想出了一个解决方案,但需要注意的是:我没有使用 sbt.

Ok, I figured out a solution with the following caveat: I'm not using sbt.

我们先写黄瓜的功能和步骤.然后我们会写一个Runner".类,它将由 JUnit runner 运行(这将忽略黄瓜的存在)

We will write cucumber features and steps first. Then we will write a "Runner" class, that will be run by JUnit runner (which will be oblivious to the presence of cucumber)

第 1 步.写黄瓜的功能和步骤只靠一件事!

Step 1. Depend only on one thing for writing cucumber features and steps!

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

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

Step 2: Now we depend on junit (for writing the runner of our tests) and cucumber-junit connection library that will allow us to tell JUni to run our cucumber tests:

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

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

Step 3: Write feature and steps definitions (they should be placed in the same folder in tests in my experience):

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

// MySteps.scala
...

第 4 步:编写我们的测试runner:

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

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

Step 5: (optional) Integration with IntelliJ

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

a) Enable JUnit in IntelliJ. This will allow us to run our cucumber tests by running our junit runner. Beautiful!

  1. 文件

设置...

插件

搜索JUnit";并确保它已启用

Search for "JUnit" and make sure it's enabled

现在我们可以通过简单地在 .feature 文件上右击 并选择运行来运行我们的黄瓜测试!

Now we can run our cucumber tests by simply right clicking on the .feature file and selecting Run!

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

b) Enable Cucumber for Scala IntelliJ plugin. (make sure Scala plugin is enabled). This enables IntelliJ to determine how to associate feature files with scala files. Without this your feature files will always be highlighted in yellow with an error undefined step reference:

  1. 文件

设置...

插件

浏览存储库...

搜索Cucumber for Scala"

search for "Cucumber for Scala"

安装 Cucumber for Scala 插件

重启 IntelliJ.

Restart IntelliJ.

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

Now your feature files will be highlighted properly!

有用的资源

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

这篇关于您如何使用 Scala 2.11 和 sbt 0.13 运行 cucumber?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆