黄瓜junit runner java.lang.NoSuchMethodError:

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21738543/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 10:25:17  来源:igfitidea点击:

cucumber junit runner java.lang.NoSuchMethodError:

javamavenjunitcucumbercucumber-jvm

提问by Onizuka

Trying to implement cucumber to do some automated tests. jUnit tests. I've created 2 files and edited pom.xml that comes with maven project to add dependencies. Content is shown below. The first of two files are cucumber .feature files, which is a gherkin of plain language. The other is CukesRunner.java

尝试实现黄瓜来做一些自动化测试。jUnit 测试。我创建了 2 个文件并编辑了 maven 项目附带的 pom.xml 以添加依赖项。内容如下所示。两个文件中的第一个是cucumber .feature 文件,这是一个简单的语言。另一个是 CukesRunner.java

When I run my tests using Project -> Run as ... -> Maven testit works as expected.

当我使用Project -> Run as ... -> Maven test它运行我的测试时,它按预期工作。

However when I ran the CukesRunner.java file using Eclipse the Eclipse JUnit GUI, I get an error:

但是,当我使用 Eclipse 和 Eclipse JUnit GUI 运行 CukesRunner.java 文件时,出现错误:

java.lang.NoSuchMethodError: org.junit.runner.Description.createSuiteDescription(Ljava/lang/String;Ljava/io/Serializable;[Ljava/lang/annotation/Annotation;)Lorg/junit/runner/Description;
    at cucumber.runtime.junit.FeatureRunner.getDescription(FeatureRunner.java:43)
    at cucumber.api.junit.Cucumber.describeChild(Cucumber.java:77)
    at cucumber.api.junit.Cucumber.describeChild(Cucumber.java:41)
    at org.junit.runners.ParentRunner.getDescription(ParentRunner.java:226)
    ... 

pom.xml:

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.bdd</groupId>
  <artifactId>airportparking</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>airportparking</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.1.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.1.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.rubiconproject.oss</groupId>
            <artifactId>jchronic</artifactId>
            <version>0.2.6</version>
            <scope>test</scope>
        </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.2</version>
        <scope>test</scope>
    </dependency>
  </dependencies>
</project>


CukesRunner.java:


CukesRunner.java:

package com.bdd.airportparking;

import cucumber.api.junit.*;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@Cucumber.Options(
        format={"pretty", "html:target/cucumber"},
        features="src/test/resources"
        )
public class CukesRunner {

}


ValetParking.feature:


代客泊车功能:

Feature: Valet Parking
    As a traveler
    In order to determine where to park my car
    I want to know the cost of valet parking

Scenario: Calculate valet parking cost for half an hour
    When I park my car in the Valet Parking Lot for 30 minutes
    Then I will have to pay 


Output when running CukesRunner.javaas a Junit Test:


CukesRunner.java作为 a 运行时的输出Junit Test

java.lang.NoSuchMethodError: org.junit.runner.Description.createSuiteDescription(Ljava/lang/String;Ljava/io/Serializable;[Ljava/lang/annotation/Annotation;)Lorg/junit/runner/Description;
    at cucumber.runtime.junit.FeatureRunner.getDescription(FeatureRunner.java:43)
    at cucumber.api.junit.Cucumber.describeChild(Cucumber.java:77)
    at cucumber.api.junit.Cucumber.describeChild(Cucumber.java:41)
    at org.junit.runners.ParentRunner.getDescription(ParentRunner.java:226)
    at org.junit.runner.Runner.testCount(Runner.java:38)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.countTestCases(JUnit4TestClassReference.java:30)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.countTests(RemoteTestRunner.java:487)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:455)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


How I structured my project in eclipse:http://postimg.org/image/vf6tlw7el/full/


我如何在 Eclipse 中构建我的项目:http : //postimg.org/image/vf6tlw7el/full/

回答by Stefan Jansen

Updating your junit version and maybe also your surefire plugin will fix this problem.

更新您的 junit 版本,也许还有您的 surefire 插件可以解决这个问题。

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>

For surefire:

万无一失:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.16</version>
        </plugin>
    </plugins>
</build>

回答by Nick Grealy

Different story but same issue... developing a Jenkins plugin, using gradle, had the latest junit:junit:4.12library on my classpath...

不同的故事,但同样的问题……使用 gradle 开发 Jenkins 插件,junit:junit:4.12在我的类路径上有最新的库……

The issue was being caused by the junit:junit-dep:4.10library, "aka"...

问题是由junit:junit-dep:4.10图书馆引起的,“又名”......

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit-dep</artifactId>
    <version>4.10</version>
    <scope>test</scope>
</dependency>

After explicitly removing it from my configuration classpath, I no longer have the issue.

从我的配置类路径中明确删除它后,我不再有这个问题。

回答by user3640657

I faced the same issue and i found that i have configured both junit 4.10, and 4.11 in my build path, Adhering to junit 11, resolved the issue.

我遇到了同样的问题,我发现我在构建路径中配置了 junit 4.10 和 4.11,坚持使用 junit 11,解决了这个问题。

回答by Rohit labhe

<dependencies>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.2</version>
        <scope>test</scope>
    </dependency>

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

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.github.mkolisnyk</groupId>
        <artifactId>cucumber-reports</artifactId>
        <version>0.0.11</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.2</version>
            <configuration>
                <encoding>UTF-8</encoding>
                <source>1.6</source>
                <target>1.6</target>
                <compilerArgument>-Werror</compilerArgument>
            </configuration>
        </plugin>
    </plugins>
</build>

回答by user9636139

I have updated my junit driver from 4.9 to 4.11; it is absolutely a junit driver problem, so just update it, and you will get it.

我已将 junit 驱动程序从 4.9 更新到 4.11;这绝对是junit驱动程序的问题,所以只需更新它,你就会得到它。

回答by Jai

Faced same issue and is resolved by using the JUnit version to 4.11 or higher. Ref: https://groups.google.com/forum/#!topic/cukes/et3rd_0LVRU

遇到了同样的问题,并通过使用 JUnit 版本到 4.11 或更高版本来解决。参考:https: //groups.google.com/forum/#!topic/cukes/ et3rd_0LVRU

回答by Tes

I had the same issue and got fixed once I configured the latest version. The issue was on junit version 4.10. the latest version from 4.11 works good

我遇到了同样的问题,并在配置最新版本后得到解决。问题出在 junit 4.10 版上。4.11 的最新版本运行良好

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.11</version>
    <scope>test</scope>
</dependency>