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

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

问题描述

我尝试用Java和Maven构建我的第一个可执行规范。我创建了一个具有此结构的简单项目:

 规范
| -src
| -test
| -java
| -mypackage
| -MyFeatureTest.java
| -resources
| -MyFeature.feature
pre>

在junit测试中 MyFeatureTest.java 我有:

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

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

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

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

我试图将其修改为

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

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

 < 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>

我缺少一些东西吗?



strong>更新我缺少的东西:黄瓜功能文件必须在子目录 src / test / resources / mypackage /



我可以运行我的功能测试,当我把它们放在同一个目录 src / main / test / ,所以它不是一个阻碍我。但我想了解整个设置。

解决方案

看看我的问题在这里



您可以通过在选项注释中设置feature属性来指定类路径上的位置。

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

编辑:



在新版本中的代码是

  @CucumberOptions(features =src / test / resources)


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

In the junit test MyFeatureTest.java I have this:

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

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

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"})

I tried to modify that to

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

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>

Am I missing something?

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.

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.

解决方案

Take a look at my question here:

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

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

Edit:

in new versions code is

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

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

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