我是第一次创建Cucumber Project。 我正在使用Eclipse。我还没有创建Maven项目,我正在遵循一些教程并创建了Java Project,在这里我手动添加了JAR文件。 JAR文件列表: 黄瓜芯-4.0.0.jar 黄瓜java-4.0.0.jar 黄瓜junit-4.0.0.jar 黄瓜jvm-deps-1.0.6.jar 小黄瓜6.0.0.jar junit-4.12.jar mockito-all-1.10.19.jar
我已经创建了Feature File: 功能:Google主页 此功能可验证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 Test运行。然后我得到错误,我将在帖子末尾添加错误。
我不认为原因是我没有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
答案 0 :(得分:0)
如果您在Maven Central上检查了黄瓜的POM,您会发现它依赖于Gherkin 5.1.0而不是6.0.0。
https://search.maven.org/artifact/io.cucumber/cucumber-jvm/4.0.0/jar
我建议您使用一种工具进行依赖项管理,而不要手动收集jar文件。 maven和gradle都是绝佳的选择。