简体   繁体   English

黄瓜框架在运行测试时抛出错误

[英]Cucumber framework throwing an error while running tests

I am using Cucumber framework for writing my ATDD's. 我正在使用Cucumber框架来编写我的ATDD。 I am getting the below error when trying to run Cucumber test. 尝试运行Cucumber测试时,我收到以下错误。

[INFO] Running my.package.RunCukesTests
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.146 s <<< FAILURE! - in my.package.RunCukesTests
[ERROR] initializationError(my.package.RunCukesTests)  Time elapsed: 0.005 s  <<< ERROR!
java.lang.NoClassDefFoundError: io/cucumber/stepexpression/TypeRegistry
Caused by: java.lang.ClassNotFoundException: io.cucumber.stepexpression.TypeRegistry

[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Errors: 
[ERROR]   RunCukesTests.initializationError » NoClassDefFound io/cucumber/stepexpression...
[INFO] 
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE

Below are the Cucumber dependencies: 以下是Cucumber依赖项:

<properties>
<cucumber.version>3.0.2</cucumber.version>
</properties>
<dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java8</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-picocontainer</artifactId>
        <version>1.2.5</version>
        <scope>test</scope>
    </dependency>

RunCuckesTest.java RunCuckesTest.java

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

@RunWith(Cucumber.class)
@CucumberOptions(plugin = { "html:target/test_results/html/TestRunner/cucumber-html-report",
        "json:target/test_results/json/TestRunner-reports.json", "pretty" }, tags = { "" }, features = {
                "src/test/resources/" }, glue = { 
                        "glue/package/steps",
                        "glue/package1/steps" })
public class RunCukesTests {
}

When searching in threads with similar exceptions I see that this might cause because of multiple dependencies or when using different versions mismatch. 在具有类似异常的线程中搜索时,我发现这可能是由于多个依赖项或使用不同版本不匹配时导致的。 but here I am using same versions and I am not sure where is the issue when I am using the same versions. 但在这里我使用相同的版本,我不知道在使用相同版本时问题出在哪里。

Any help is really appreciated. 任何帮助都非常感谢。 Thanks in Advance. 提前致谢。

Key Point: We shall not mix info.cukes & io.cucumber dependencies specially their versions! 关键点:我们不会特别混合info.cukes和io.cucumber依赖项的版本! Doing so can cause unpredictable outcome. 这样做会导致不可预测的结果。

Solution: You may prefer below correct set of io.cucumber dependencies and update cucumber v as per your framework need. 解决方案:您可能更喜欢下面正确的io.cucumber依赖项集,并根据您的框架需要更新黄瓜v。

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

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-picocontainer</artifactId>
    <version>4.2.6</version>
</dependency>

I have almost same configuration and its working fine for me. 我有几乎相同的配置,它的工作正常。 Please user below dependency and verify if its any other issue or not. 请用户在以下依赖关系并验证是否有任何其他问题。

My pom.xml dependency 我的pom.xml依赖项

       <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>2.4.0</version>
        </dependency>


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


      <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>1.2.5</version>
        </dependency>

Now if you are using Cucumber 3 then you have to update the pico container version(2.15) too. 现在,如果您使用的是Cucumber 3,那么您还必须更新pico容器版本(2.15)。

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

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