Can't execute feature in cucumber jvm

2019-07-22 20:45发布

I am very new to using cucumber (started today).

It seems simple enough but I am having issues running a basic feature.

Feature: Proof of concept that my framework works

Scenario: My first test

Given this is my first step
When this is my second step
Then this is my final step

I know there is no code for it to test, but I wanted it to return the fact that the scenarios are undefined.

I did some research and realised I had a .jar file which was unnecessary, I have since removed that.

I still have the following issue:

Exception in thread "main" java.lang.NoClassDefFoundError: gherkin/lexer/Encoding

Caused by: java.lang.ClassNotFoundException: gherkin.lexer.Encoding

There some more info from the exception.

Is there any other info I should provide?

Any help would be appreciated

4条回答
我欲成王,谁敢阻挡
2楼-- · 2019-07-22 21:16

Rather than downloading individual jars, use a package manager to download the dependencies.

Using Maven, add the following dependencies to the pom.xml:

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>2.3.1</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>2.3.1</version>
    <scope>test</scope>
</dependency>

NB. This is currently the latest version.

Make sure to use the same version for all Cucumber dependencies.

查看更多
Luminary・发光体
3楼-- · 2019-07-22 21:18

Its an setup issue as it is not finding the required cucumber classes to interpret gherkin statements. Provide more info on the files you included in the setup.

查看更多
Viruses.
4楼-- · 2019-07-22 21:24

Make sure you have the cucumber java libraries in your CLASSPATH.

查看更多
该账号已被封号
5楼-- · 2019-07-22 21:33

I had this same problem when running through the First Steps chapter in The Cucumber for Java book.

It says to download the latest version of the Gherkin jar (among others) from

http://repo1.maven.org/maven2/info/cukes/gherkin/

Below is the listing, where, on the webpage, each one is a directory-link containing the jar. My mistake was thinking that the bottom-most version is the most recent version. It's not. For all of the other jars, the bottom-most is indeed the most recent version.

When using the bottom-most Gherkin jar, I get the CNFX exactly as you describe:

Exception in thread "main" java.lang.NoClassDefFoundError: gherkin/lexer/Encoding
Caused by: java.lang.ClassNotFoundException: gherkin.lexer.Encoding

The version-number listing, as on the above webpage:

2.10.0/
2.11.0/
2.11.1/
2.11.2/
2.11.4/
2.11.5/
2.11.6/
2.11.7/
2.11.8/
2.12.0/
2.12.1/
2.12.2/
2.4.16/
2.4.17/
2.4.18/
2.4.19/
2.4.20/
2.4.21/
2.5.0/
2.5.1/
2.5.2/
2.5.3/
2.5.4/
2.6.0/
2.6.1/
2.6.2/
2.6.3/
2.6.4/
2.6.5/
2.6.6/
2.6.7/
2.6.8/
2.6.9/
2.7.0/
2.7.1/
2.7.2/
2.7.3/
2.7.4/
2.7.5/
2.7.6/
2.7.7/
2.8.0/
2.9.0/
2.9.1/
2.9.2/
2.9.3/
查看更多
登录 后发表回答