如何使用 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")
相关文章