Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
313 views
in Technique[技术] by (71.8m points)

java - How do I set the path to my Cucumber features using cucumber-junit?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...