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

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

问题描述

有人有一个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运行程序运行(这将忽略黄瓜的存在)

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(用于编写测试的运行程序)和cumulage-junit连接库,这些库将允许我们 tell 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步:编写测试程序运行程序:

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. 文件

  1. File

设置...

插件

搜索"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)为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. 文件

  1. Files

设置...

插件

浏览存储库...

搜索"Scala的黄瓜"

search for "Cucumber for Scala"

安装Cucumber for Scala插件

重新启动IntelliJ.

Restart IntelliJ.

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

Now your feature files will be highlighted properly!

有用的资源

  1. 有关黄瓜的Java教程,这使我想到了以下解决方案: https://gitter.im/cucumber/chat
  2. 目录结构(请注意,在scala中,我们似乎需要将要素文件和步骤文件都放置在同一文件夹中:但是,各个运行者的想法都很有趣):
  1. Java tutorial for cucumber, that led me to this solution: https://c0deattack.wordpress.com/2012/03/28/cucumber-jvm-with-cucumber-java-cucumber-junit-example/
  2. Cucumber chat room where people are super helpful: https://gitter.im/cucumber/chat
  3. Directory structure (note that in scala we seem to need to place both feature and steps files into the same folder: however the idea of individual runners is interesting): http://www.hascode.com/2014/12/bdd-testing-with-cucumber-java-and-junit/#Directory_Structure

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

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