gpt4 book ai didi

java - JUnit Test Cucumber 中的初始化错误(NoClassFound - IGherkinDialectProvider)

转载 作者:太空宇宙 更新时间:2023-11-04 10:09:54 26 4
gpt4 key购买 nike

我是第一次创建 Cucumber 项目。我正在使用 Eclipse。我还没有创建 Maven 项目。我正在遵循一些教程并创建 Java 项目。我手动添加了 JAR 文件。JAR 文件列表: cucumber 核心-4.0.0.jar cucumber -java-4.0.0.jar cucumber -junit-4.0.0.jar cucumber -jvm-deps-1.0.6.jar小 cucumber -6.0.0.jarjunit-4.12.jarmockito-all-1.10.19.jar

我已经创建了功能文件: 功能:谷歌主页 此功能验证 Google 主页上的功能

Scenario: Check that main elements on Google Homepage are displayed
Given I launch Chrome browser
When I open Google Homepage
Then I verify that the page displays search text box
And the page displays Google Search button
And the page displays Im Feeling Lucky button

我已经创建了 TestRunner 类

package testRunners;

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

@RunWith(Cucumber.class)
@CucumberOptions(,features="resources/features", glue="")
public class TestRunner_FirstScenario {
}

我尝试将此类作为 JUnit 测试运行。然后我收到错误,我将在帖子末尾添加错误。

我不认为原因是我没有 StepDefinitions 类。我认为 JAR 版本存在一些兼容性问题,但我正在使用最新版本。

错误是:

TestRunner_FirstScenario
testRunners.TestRunner_FirstScenario
initializationError(testRunners.TestRunner_FirstScenario)
java.lang.NoClassDefFoundError: gherkin/IGherkinDialectProvider

at cucumber.runtime.RuntimeOptionsFactory.create(RuntimeOptionsFactory.java:23)

at cucumber.api.junit.Cucumber.<init>(Cucumber.java:84)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)

at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)

at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)

at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)

at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)

at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)

at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:87)

at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:73)

at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:46)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:522)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)

Caused by: java.lang.ClassNotFoundException: gherkin.IGherkinDialectProvider

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

... 19 more

最佳答案

如果你在mavencentral上检查cucumber的POM,你会发现它依赖于Gherkin 5.1.0而不是6.0.0。

https://search.maven.org/artifact/io.cucumber/cucumber-jvm/4.0.0/jar

我建议您使用依赖管理工具,而不是手动收集 jar 文件。 maven 和 gradle 都是不错的选择。

关于java - JUnit Test Cucumber 中的初始化错误(NoClassFound - IGherkinDialectProvider),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52476384/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com