Cant run feature in Cucumber

2019-06-24 00:44发布

Im having issues running a feature in Cucumber, the feature is very basic as it's from a tutorial.

It is not defined and is as follows:

Feature: Proof that my concept works

Scenario: My first test
 Given this is my first step
 When this is my second step
 Then this is my final step

My Cucumber runner class is as follows:

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

 @RunWith(Cucumber.class)
 @Cucumber.Options(
    format = {"pretty", "json:target/"},
    features = {"src/cucumber/"}
    )
 public class CucumberRunner {

 }

Also the external .jar files that I have in the project are as follows:

image

The exception that I'm getting is:

Exception in thread "main" cucumber.runtime.CucumberException: Failed to instantiate public cucumber.runtime.java.JavaBackend(cucumber.runtime.io.ResourceLoader) with [cucumber.runtime.io.MultiLoader@75d837b6]

I've tried to look around online for the solution to this problem but have not had any luck.

I've also discussed with the OP of the tutorial and I'm still awaiting feedback but it has been a while.

6条回答
ゆ 、 Hurt°
2楼-- · 2019-06-24 01:22

The only reason for this error is the version of all the cucumber libraries are not same. It should be like this:

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-java8</artifactId>
    <version>4.2.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-picocontainer</artifactId>
    <version>4.2.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-testng</artifactId>
    <version>4.2.6</version>
        <exclusions>
            <exclusion>
                <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
            </exclusion>
        </exclusions>
</dependency>
查看更多
Root(大扎)
3楼-- · 2019-06-24 01:26

I ran into a similar issue and got the same error as you did.

Firstly mention the path to the feature file features = {"src/cucumber/myfile.feature"} Anyway, that didn't cause the error.

To just run your Cucumber runner class, all the dependencies you need are

cucmber-junit cucumber-java and junit.

I had an additional cucumber-guice which was creating the problem and once I removed it, the error went away and runner was executed successfully.

From the link to the image you have mentioned it looks like you are not using cucumber-guice but still I would recommend you remove other unnecessary cucumber dependencies and try again.

查看更多
Bombasti
4楼-- · 2019-06-24 01:30

1, I ran into this too few days ago, its simple just remove cucumber-Spring from the dependency. 2 If that doesn't work try updating cucumber-core, cucumber-junit, and cucumber-java all version 1.2.3

查看更多
小情绪 Triste *
5楼-- · 2019-06-24 01:31

This worked for me, I hope it will work for you as well.

Update your Cucumber dependencies in pom.xml i.e

  • cucumber-java (1.2.2)
  • cucumber-jvm (1.2.2)
  • cucumber-junit (1.2.2)

And update your Junit dependency as well. (4.11).

查看更多
贼婆χ
6楼-- · 2019-06-24 01:33

I believe the issue is that many of the cucumber add-ins, such as cucumber-testng, cucumber-spring, and (in my case) cucumber-guice, expect the corresponding module they link to be included as well. But apparently the cucumber experts decided not to include this dependency in their pom.xml files, so the problem doesn't manifest itself until runtime.

So (to answer Eugene S's question under LING's answer) if you want to actually use guice with cucumber, you need to also add guice itself as a dependency.

查看更多
一纸荒年 Trace。
7楼-- · 2019-06-24 01:45

First Thing : We would request you to use Cucumber v >=4.0.0 as you are using pretty old dependency(v1.2.5) of Cucumber.

Key Point : We shall not mix direct & transitive dependencies specially their versions! Doing so can cause unpredictable outcome.

Solution: Please remove. cucumber-core, cucumber-java, cucumber-jvm-deps, gherkin and cucumber-html. They're transitive dependencies and will be provided by your direct dependencies.

You can add below set of cucumber minimal dependencies.

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

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-picocontainer</artifactId>
    <version>4.2.6</version>
    <scope>test</scope>
</dependency>
查看更多
登录 后发表回答