如何使用 cucumber-junit 设置 Cucumber 功能的路径? [英] How do I set the path to my Cucumber features using cucumber-junit?

查看:19
本文介绍了如何使用 cucumber-junit 设置 Cucumber 功能的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 Java 和 Maven 构建我的第一个可执行规范.我用这种结构创建了一个简单的项目:

I try to build my first executable specifications with Java and Maven. I created a simple project with this structure:

specification
|-src
  |-test
    |-java
      |-mypackage
        |-MyFeatureTest.java
    |-resources
      |-MyFeature.feature

在 junit 测试 MyFeatureTest.java 我有这个:

In the junit test MyFeatureTest.java I have this:

import org.junit.runner.RunWith;
import cucumber.junit.Cucumber;

@RunWith(Cucumber.class)
public class HomepageTest {
}

现在 https://github.com/cucumber/cucumber-jvm/wiki/IDE-support 说我应该添加以下行:

Now https://github.com/cucumber/cucumber-jvm/wiki/IDE-support says that I should add the following line:

@Cucumber.Options(paths={"my/super.feature:34"})

我尝试将其修改为

@Cucumber.Options(paths={"src/test/resources/"})

但注释 @Cucumber.Options 根本不可用.我的 pom.xml 有这个依赖:

but the annotation @Cucumber.Options isn't available at all. My pom.xml has this dependencies:

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.10</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>info.cukes</groupId>
  <artifactId>cucumber-java</artifactId>
  <version>1.0.0.RC20</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>info.cukes</groupId>
  <artifactId>cucumber-junit</artifactId>
  <version>1.0.0.RC20</version>
  <scope>test</scope>
</dependency>

我错过了什么吗?

更新我遗漏了一些东西:黄瓜功能文件必须位于子目录 src/test/resources/mypackage/ 中.否则不会被junit测试拾取.

Update I was missing something: The cucumber feature file has to be in a subdirectory src/test/resources/mypackage/. Otherwise it won't be picked up by the junit test.

当我将它们放在同一目录 src/main/test/ 中时,我可以运行我的功能测试,所以这对我来说不是一个障碍.但我想了解整个设置.

I can run my feature tests when I put them in the same directory src/main/test/, so it's not a blocker for me. But I'd like to understand the whole setup.

推荐答案

看看我的问题 这里:

您可以通过在选项注释中设置特征属性来指定类路径上的位置,例如

You can specify a location on the classpath by setting the feature attribute in the options annotation like

@Cucumber.Options(features="src/test/resources")

在新版本中的代码是

@CucumberOptions(features="src/test/resources")

这篇关于如何使用 cucumber-junit 设置 Cucumber 功能的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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