java 无法运行 Cucumber 中的功能
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25847343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cant run feature in Cucumber
提问by dhali
Im having issues running a feature in Cucumber, the feature is very basic as it's from a tutorial.
我在 Cucumber 中运行某个功能时遇到问题,该功能非常基础,因为它来自教程。
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:
我的 Cucumber runner 课程如下:
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:
另外.jar
我在项目中的外部文件如下:
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]
线程“main”cucumber.runtime.CucumberException 中的异常:无法使用 [cucumber.runtime.io.MultiLoader@75d837b6] 实例化公共 Cucumber.runtime.java.JavaBackend(cucumber.runtime.io.ResourceLoader)
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.
我还与教程的 OP 进行了讨论,我仍在等待反馈,但已经有一段时间了。
回答by LINGS
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.
首先提到功能文件的路径
features = {"src/cucumber/myfile.feature"}
无论如何,这并没有导致错误。
To just run your Cucumber runner class, all the dependencies you need are
要运行您的 Cucumber runner 类,您需要的所有依赖项是
cucmber-junit
cucumber-java
and
junit
.
cucmber-junit
cucumber-java
和
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.
我有一个额外cucumber-guice
的问题,它会产生问题,一旦我删除它,错误就消失了,运行程序成功执行。
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.
从您提到的图像链接来看,您似乎没有使用,cucumber-guice
但我仍然建议您删除其他不必要的黄瓜依赖项,然后重试。
回答by Will Automatetillinfinity
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
1,前几天我也遇到了这个,很简单,从依赖中删除cucumber-Spring。2 如果这不起作用,请尝试更新黄瓜核心、黄瓜 junit 和黄瓜 Java 的所有版本 1.2.3
回答by John Chesshir
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.
我认为问题在于许多黄瓜插件,例如黄瓜测试、黄瓜弹簧和(在我的情况下)黄瓜 guice,希望它们链接的相应模块也包含在内。但是显然黄瓜专家决定不在他们的 pom.xml 文件中包含这个依赖项,所以这个问题直到运行时才会出现。
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.
因此(在 LING 的回答下回答 Eugene S 的问题)如果您想实际将 guice 与黄瓜一起使用,您还需要将 guice 本身添加为依赖项。
回答by Shivam
This worked for me, I hope it will work for you as well.
这对我有用,我希望它也对你有用。
Update your Cucumber dependencies in pom.xml i.e
更新 pom.xml 中的 Cucumber 依赖项,即
- cucumber-java (1.2.2)
- cucumber-jvm (1.2.2)
- cucumber-junit (1.2.2)
- 黄瓜-java (1.2.2)
- 黄瓜 jvm (1.2.2)
- 黄瓜junit (1.2.2)
And update your Junit dependency as well. (4.11).
并更新您的 Junit 依赖项。(4.11)。
回答by Jitendra
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>
回答by TheSociety
First Thing :We would request you to use Cucumber v >=4.0.0as you are using pretty old dependency(v1.2.5) of Cucumber.
第一件事:我们会要求您使用Cucumber v >=4.0.0,因为您正在使用Cucumber 的相当旧的依赖项(v1.2.5)。
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, gherkinand cucumber-html. They're transitive dependencies and will be provided by your direct dependencies.
解决方法:请删除。黄瓜核心、黄瓜java、黄瓜jvm-deps、小黄瓜和黄瓜html。它们是传递依赖项,将由您的直接依赖项提供。
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>
回答by Motasem Halawani
After spending a lot of time on this issue, most of the errors I was receiving were due to dependencies and dependencies versions mismatch. Adding these dependencies to pom.xml file worked for me:
在这个问题上花了很多时间之后,我收到的大多数错误都是由于依赖项和依赖项版本不匹配。将这些依赖项添加到 pom.xml 文件对我有用:
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-scala_2.11</artifactId>
<version>4.7.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-jvm -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-jvm</artifactId>
<version>4.8.1</version>
<type>pom</type>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java8 -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>4.8.1</version>
</dependency>