java - 测试运行,但是: Could not find or load main class cucumber. api.cli.Main

标签 java gradle intellij-idea cucumber

当我尝试时:

java cucumber.api.cli.Main --help

我得到:

Could not find or load main class cucumber.api.cli.Main

我的配置是:

enter image description here

我真的不知道是什么问题...我的测试运行成功。

我使用 gradle 和 IntelliJ

我希望有人能帮助我:)

------------编辑----------------

我的build.gradle:

plugins {
    id 'java'
}

group 'CucumberWithSeleniumTest'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    testCompile 'io.cucumber:cucumber-java:2.4.0'
    testCompile 'io.cucumber:cucumber-junit:2.4.0'
    compileOnly group: 'info.cukes', name: 'gherkin', version: '2.12.2'
    implementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.5.3'
    testCompile group: 'net.sourceforge.cobertura', name: 'cobertura', version: '2.1.1'
    compile group: 'io.cucumber', name: 'cucumber-html', version: '0.2.7'
    compileOnly group: 'io.cucumber', name: 'cucumber-jvm-deps', version: '1.0.6' 
    compile group: 'net.masterthought', name: 'cucumber-reporting', version: '4.2.2'
    testCompile group: 'org.hamcrest', name: 'hamcrest-core', version: '1.3' 
}

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']
        }
    }
}

还有我的项目文件夹:

enter image description here

------------------------edit2-------------------- --- 此处:

C:\Users\...\CucumberWithSeleniumTest>gradle cucumber
Task :cucumber
Feature: Reset functionality on login page of Application

  Scenario Outline: Verification of Reset button # src/test/resources/MyTest.feature:3
    Given Open the Firefox and launch the application
    When Enter the <username> and <password>
    Then Reset the credential

    Examples:

  Scenario Outline: Verification of Reset button      # src/test/resources/MyTest.feature:10
    Given Open the Firefox and launch the application # null
    When Enter the User1 and password1                # null
    Then Reset the credential                         # null

  Scenario Outline: Verification of Reset button      # src/test/resources/MyTest.feature:11
    Given Open the Firefox and launch the application # null
    When Enter the User2 and password2                # null
    Then Reset the credential                         # null

  Scenario Outline: Verification of Reset button      # src/test/resources/MyTest.feature:12
    Given Open the Firefox and launch the application # null
    When Enter the User3 and password3                # null
    Then Reset the credential                         # null

3 Scenarios (3 undefined)
9 Steps (9 undefined)
0m0,019s


You can implement missing steps with the snippets below:

@Given("^Open the Firefox and launch the application$")
public void open_the_Firefox_and_launch_the_application() {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^Enter the User(\\d+) and password(\\d+)$")
public void enter_the_User_and_password(int arg1, int arg2) {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^Reset the credential$")
public void reset_the_credential() {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8

BUILD SUCCESSFUL in 21s
3 actionable tasks: 2 executed, 1 up-to-date

最佳答案

好的,我发现了一个问题,我用junit运行我的测试

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']
        }
    }
}

如果我改变:args = ['--plugin', 'pretty', '--glue', 'gradle.cucumber', 'src/test/resources']args = ['--help'] 有效

但是没有junit我不知道

关于java - 测试运行,但是: Could not find or load main class cucumber. api.cli.Main,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53539969/

相关文章:

java - 无法解析项目 : Android library and Java library module dependency

android - IntelliJ Idea Android 项目 : Gradle project sync failed

java - 寻找与数据库设计相关的方式

java - 如何通过 2 个连接的蓝牙设备发送数据

linux - Android Studio 3.2.1 - 无法将项目与 gradle 文件同步 : Argument for @NotNull parameter 'message' of . .. 不能为空

jenkins - 使用Gradle的Artifactory Jenkins集成

android - android studio中clean项目和rebuild项目的区别

maven - 如何克服IntelliJ中的“找不到存储库”错误

java - java中不带循环的If中断

java - .java.security.NoSuchAlgorithmException : algorithm RSA/PKCS1 is not available from provider Cryptix