简体   繁体   English

测试运行,但是:无法找到或加载主类cucumber.api.cli.Main

[英]Test run, but: Could not find or load main class cucumber.api.cli.Main

When I try: 当我尝试:

java cucumber.api.cli.Main --help

I get: 我明白了:

Could not find or load main class cucumber.api.cli.Main 无法找到或加载主类cucumber.api.cli.Main

My configurations are: 我的配置是:

在此输入图像描述

I dont really know what is the problem... My test run successful. 我真的不知道问题是什么......我的测试成功了。

I use gradle and IntelliJ 我使用gradle和IntelliJ

I hope someone could help me :) 我希望有人可以帮助我:)

------------edit----------------- - - - - - - 编辑 - - - - - - - - -

My build.gradle: 我的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']
        }
    }
}

And my project folder: 和我的项目文件夹:

在此输入图像描述

---------------------------edit2---------------------- 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

Okay, I found one problem, I run my test with junit 好的,我发现了一个问题,我用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']
        }
    }
}

If I change: args = ['--plugin', 'pretty', '--glue', 'gradle.cucumber', 'src/test/resources'] to args = ['--help'] it works 如果我改变: args = [' - plugin','pretty',' - glue','gradle.cucumber','src / test / resources']args = [' - help']它的工作原理

but without junit I have no idea 但没有junit我不知道

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Cucumber 测试 - 找不到类 cucumber.api.cli.Main - Cucumber test - could not find classs cucumber.api.cli.Main Java Cucumber - 错误:无法找到或加载主类 Cucumber.api.cli.Main - Java cucumber - Error: Could not find or load main class cucumber.api.cli.Main 错误:无法找到或加载主类cucumber.api.cli.Main - Error: Could not find or load main class cucumber.api.cli.Main 无法在Eclipse中使用Gradle运行黄瓜功能文件。 我收到“错误:无法找到或加载主类Cucumber.api.cli.Main”错误 - Unable to run cucumber feature file using gradle in Eclipse. I am getting “Error: Could not find or load main class cucumber.api.cli.Main” error 基本黄瓜测试项目-如何运行javacumber.api.cli.Main? - Basic Cucumber test project - how to run java cucumber.api.cli.Main? 错误:无法找到或加载主类 cucumber.cli.Main - Error: Could not find or load main class cucumber.cli.Main CLI runner cucumber.api.cli.Main 找不到步骤定义 - CLI runner cucumber.api.cli.Main cannot find step definitions javacumul.api.cli.main命令行用法 - java cucumber.api.cli.main command line usage Java Cucumber CLI(cucumber.api.cli.Main)的--glue选项的语法 - Syntax of --glue option for Java Cucumber cli (cucumber.api.cli.Main) 再次找不到或加载主类测试 - Could not find or load main class test (again)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM