简体   繁体   中英

InitializationError in JUnit Test Cucumber ( NoClassFound - IGherkinDialectProvider )

I'm creating Cucumber Project for the first time. I'm using Eclipse. I've not created Maven project.I'm following some tutorials and created Java Project.Where I added JAR files manually. List of JAR files: cucumber-core-4.0.0.jar cucumber-java-4.0.0.jar cucumber-junit-4.0.0.jar cucumber-jvm-deps-1.0.6.jar gherkin-6.0.0.jar junit-4.12.jar mockito-all-1.10.19.jar

I've created Feature File : Feature: Google Homepage This feature verifies the functionality on Google Homepage

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 

I've created TestRunner Class

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 {
}

I try to run this class as JUnit Test. Then I get error,I'll add error at the end of the post.

I don't think the reason is that I don't have StepDefinitions class.I think there are some compatibility problems with JAR versions, but I'm using the newest versions.

Error is:

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

If you check the POM of cucumber on maven central you can see that it has a dependency on Gherkin 5.1.0 rather then 6.0.0.

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

I would recommend that you use a tool for dependency management rather then manually collecting jar files. Both maven and gradle are excellent choices.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM