Intellij idea 如何在Intellij上为Cucumber Java功能设置多个步骤定义

Intellij idea 如何在Intellij上为Cucumber Java功能设置多个步骤定义,intellij-idea,cucumber,bdd,cucumber-jvm,cucumber-java,Intellij Idea,Cucumber,Bdd,Cucumber Jvm,Cucumber Java,我正在尝试为几个功能创建几个步骤定义类。这是我的项目结构: . ├── CucumberPOC.iml └── src └── test ├── CucumberRunner.java └── features ├── CheeseStepDefinition.java ├── StepDefinition.java ├── cheese.feature └──

我正在尝试为几个功能创建几个步骤定义类。这是我的项目结构:

.
├── CucumberPOC.iml
└── src
    └── test
        ├── CucumberRunner.java
        └── features
            ├── CheeseStepDefinition.java
            ├── StepDefinition.java
            ├── cheese.feature
            └── myfeature.feature
它是CucumberRunner.java类:

package test;

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

@RunWith(Cucumber.class)
@CucumberOptions(
        format = {" pretty", "json:target/cucumber.js"},
        features = { "src/test/" }
)
public class CucumberRunner {
}
有两个步骤定义类。运行cheese.feature时,出现错误:

/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java ...
Testing started at 9:26 AM ...

Undefined step: Given  I go to google

Undefined step: When  I ask for cheese

Undefined step: Then  I should see many offers


1 scenario (0 passed)


3 steps (0 passed)


1 Scenarios (1 undefined)
3 Steps (3 undefined)
0m0.000s


You can implement missing steps with the snippets below:

@Given("^I go to google$")
public void I_go_to_google() throws Throwable {
    // Express the Regexp above with the code you wish you had
    throw new PendingException();
}

@When("^I ask for cheese$")
public void I_ask_for_cheese() throws Throwable {
    // Express the Regexp above with the code you wish you had
    throw new PendingException();
}

@Then("^I should see many offers$")
public void I_should_see_many_offers() throws Throwable {
    // Express the Regexp above with the code you wish you had
    throw new PendingException();
}


Process finished with exit code 0
但步骤在CheeseStepDefinition中定义:

package test.features;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;

public class CheeseStepDefinition {

    WebDriver driver = null;

    @Given("^I go to google$")
    public void I_go_to_google() throws Throwable {
        driver = new HtmlUnitDriver();
        driver.get("http://www.google.com");
    }

    @When("^I ask for cheese$")
    public void I_ask_for_cheese() throws Throwable {
        WebElement search = driver.findElement(By.name("q"));
        search.sendKeys("cheese");
        search.submit();
    }

    @Then("^I should see many offers$")
    public void I_should_see_many_offers() throws Throwable {
        System.out.println(driver.getTitle());
        driver.close();
    }
}
所以我不知道为什么cucumber java没有看到它的步骤定义。我需要进行其他配置吗?我运行myfeature.feature,一切正常

工具信息。 我正在使用这个罐子:

.
├── cucumber-core-1.1.5.jar
├── cucumber-html-0.2.3.jar
├── cucumber-java-1.1.5.jar
├── cucumber-junit-1.1.5.jar
├── cucumber-jvm-deps-1.0.5.jar
├── gherkin-2.12.1.jar
├── hamcrest-all-1.3.jar
├── jsoup-1.8.3.jar
├── junit-4.12.jar
└── selenium-server-standalone-2.47.1.jar
IDE是Mac上的Intellij14.1社区


如果你需要任何其他信息,请告诉我

您需要在cucumber选项中定义“粘合”选项

在跑步者中,您可以定义胶水和功能的位置。>>>粘合是步骤定义,特征是特征

在您的情况下,您的步骤定义与功能位于同一位置,但您必须将其告知跑步者

你的情况应该是这样的

@CucumberOptions(
    format = {" pretty", "json:target/cucumber.js"},
    features = { "src/test/"}, glue ={ "src/test/"  })

请注意,

按如下方式重新排列您的文件:

└── src
    └── test
        ├── java
            ├── <project>
                 ├── CheeseStepDefinition.java
                 ├── StepDefinition.java
                 └── CucumberRunner.java
        ├── resources
            ├── <project>
                 ├── cheese.feature
                 └── myfeature.feature
└── src
└── 测试
├── JAVA
├── 
├── CheeseStepDefinition.java
├── StepDefinition.java
└── CucumberRunner.java
├── 资源
├── 
├── 奶酪特征
└── myfeature.feature
应该是项目的目录名。 将
src/test/java
文件夹标记为
testroot
。 将
src/test/resources
文件夹标记为
test resources root

要标记文件夹:在IntelliJ中,右键单击左侧项目视图中的文件夹,然后选择将目录标记为,然后选择相应的选项。

是您的IntelliJ项目中标记为“测试源文件夹”的
/src/test
吗?@troig我如何标记我的测试文件夹。我对intellijI比较新,我想我能帮你。您需要打开项目结构/模块,在那里之后,将目录标记为
Tests
。你能试试吗?