简体   繁体   English

运行 Cucumber JUnit 测试时出现 InitializationError

[英]InitializationError while running Cucumber JUnit Tests

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

@RunWith(Cucumber.class)
@CucumberOptions(
        format={"pretty"},
        features= "src/features/"
        )
public class cucumberRunner {

}

The problem is that your class is located in the package 'cucumber'.问题是您的课程位于“cucumber”包中。 Either rename the package or move your step-definitions and other glue-code to a sub-package like 'cucumber.steps' and restrict the lookup of glue-code to this package:重命名包或将您的步骤定义和其他胶水代码移动到像“cucumber.steps”这样的子包中,并将胶水代码的查找限制在此包中:

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

 @RunWith(Cucumber.class)
 @CucumberOptions(
    format={"pretty"},
    features= "src/features/",
    glue = "cucumber.steps")
 public class cucumberRunner {}

It has something do with the jars.Use this below dependency in your pom.xml file.它与罐子有关。在 pom.xml 文件中使用以下依赖项。 1.2.5 works! 1.2.5 有效! For other versions, I was getting the same error but when I add this dependency, it worked for me without any errors!对于其他版本,我遇到了同样的错误,但是当我添加这个依赖项时,它对我有用,没有任何错误!

<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>

Import following lines to your code after adding that dependency in your pom.xml file -import org.junit.runner.RunWith;在您的 pom.xml 文件中添加该依赖项后,将以下行导入您的代码 -import org.junit.runner.RunWith; -import cucumber.api.junit.Cucumber; -进口黄瓜.api.junit.Cucumber;

InitializationError while running Cucumber JUnit Tests I am not able to ask a question because I am new to the platform运行 Cucumber JUnit 测试时的InitializationError我无法提问,因为我是该平台的新手

    package myTestRunner;

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

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "J:\\EclipseWorkSpaces\\CucumberBDDFramework\\BDDCucucmber\\src\\main\\java\\features"
        ,glue={"J:\\EclipseWorkSpaces\\CucumberBDDFramework\\BDDCucucmber\\src\\main\\java\\stepDefinition"},
        format = {"pretty","html : test-output"}
        
        )

public class TestRunner {

}

down below I am attaching the screenshot of my folder structure and the console output:

[enter image description here][1]


  [1]: https://i.stack.imgur.com/j59XB.png

On your testRunner, make sure you import the correct Junit libraries.在您的 testRunner 上,确保您导入了正确的 Junit 库。 Once you hover your mouse on the @RunWith(Cucumber.class), eclipse will provide you with two options, make sure NOT to select "Add JUnit 4 Library to build path".将鼠标悬停在@RunWith(Cucumber.class) 上后,eclipse 将为您提供两个选项,请确保不要选择“添加 JUnit 4 库以构建路径”。

However, select "import 'RunWith'(org.junit.runner)" and import it.但是,选择“import 'RunWith'(org.junit.runner)”并导入它。 This will solve the error.这将解决错误。

"

Try importing the below,尝试导入以下内容,

import io.cucumber.junit.CucumberOptions;
import io.cucumber.junit.Cucumber;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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