无法在Eclipse中使用gradle运行黄瓜功能文件。我得到"错误:无法找到或加载主类cucumber.api.cli.Main"错误

时间:2018-05-29 18:16:58

标签: java testing gradle cucumber cucumber-java

我正在尝试在Eclipse上运行黄瓜功能文件但是会出现以下错误。 "错误:无法找到或加载主类cucumber.api.cli.Main"

Gradle代码( build.gradle

apply plugin: 'java'

configurations {
    cucumberRuntime {
        extendsFrom testRuntime
    }
}

task cucumber() {
    dependsOn assemble, compileTestJava
    doLast {
        javaexec {
            main = "cucumber.api.cli.Main"
            classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
            args = ['--plugin', 'pretty', '--glue', 'gradle.cucumber', 'src/test/resources']
        }
    }
}

dependencies {
    testCompile 'io.cucumber:cucumber-java:3.0.2'
    testCompile 'io.cucumber:cucumber-junit:3.0.2'

    testCompile 'junit:junit:4.12'
}

repositories {
    mavenCentral()
}

功能文件( add.Feature

@tag
Feature: Title of your feature
  I want to use this template for my feature file

  @tag1
  Scenario: Title of your scenario
    Given I have the calculator
    When I enter input1 and input2
    And I press add button
    Then I get output

我正确点击了要素文件。然后选择run as并按下黄瓜功能。 提前谢谢。

2 个答案:

答案 0 :(得分:2)

我忘了添加跑步者课程。 以下是跑步者类的代码。添加此类后,我可以运行功能文件

<强> runcukestest.java

package cucumber;

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

@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"pretty"})
public class runcukestest {

}

答案 1 :(得分:0)

我忘记添加跑步者课程了。以下是跑步者课程的代码。添加完此类后,我便可以运行功能文件

runcukestest.java

package cucumber;

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

@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"pretty"})
public class runcukestest {

}

它确实有助于运行功能文件。但是我遇到了与实施缺少的步骤有关的错误错误

  

”您可以在“

下面的代码片段中实施缺少的Seps

但是我已经用相同的方法创建了一个Test类