How do I set the path to my Cucumber features using cucumber-junit?(如何使用 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 功能的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 cucumber-junit 设置 Cucumber 功能的路径?


- 如何指定 CORS 的响应标头? 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- 获取数字的最后一位 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 转换 ldap 日期 2022-01-01