【问题标题】:cucumber junit runner java.lang.NoSuchMethodError:黄瓜junit runner java.lang.NoSuchMethodError:
【发布时间】:2014-03-11 09:42:57
【问题描述】:

尝试实现 cucumber 来做一些自动化测试。 jUnit 测试。我创建了 2 个文件并编辑了 maven 项目附带的 pom.xml 以添加依赖项。内容如下图。两个文件中的第一个是 cucumber .feature 文件,它是一种通俗易懂的小黄瓜。另一个是CukesRunner.java

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

但是,当我使用 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:

<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:

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 $12


Junit Test 运行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)
    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)


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

【问题讨论】:

  • 你的stepdefs在哪里?
  • @Bala 它应该在哪里?
  • 检查这个答案。它可能会帮助你。 stackoverflow.com/questions/21753267/…
  • 我遇到了同样的问题,所以我遇到了问题。我从堆栈跟踪推断您正在 Eclipse 中运行测试。我正在编辑问题以反映我的经验,如果您“运行为...-> Maven 测试”,这是可行的
  • @Onizuka,你有没有设法解决这个问题?

标签: java maven junit cucumber cucumber-jvm


【解决方案1】:

更新你的junit版本,也许你的surefire插件也能解决这个问题。

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

万无一失:

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

【讨论】:

    【解决方案2】:

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

    问题是由 junit:junit-dep:4.10 库“aka”引起的...

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

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

    【讨论】:

    • 这就是解决我的问题的方法,即摆脱 junit-dep
    【解决方案3】:

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

    【讨论】:

      【解决方案4】:
      <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>
      

      【讨论】:

      • 我已经更新了我的 POM,如下所示,它得到了解决。
      【解决方案5】:

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

      【讨论】:

      • 为什么不是 4.12 版?
      【解决方案6】:

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

      【讨论】:

        【解决方案7】:

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

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

        【讨论】:

          【解决方案8】:

          确保在 POM.xml 中使用正确的 JUnit 版本。 将其从 4.10 更改为最新的 4.11 即可。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2017-03-04
            • 2021-07-07
            • 2017-04-20
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2018-12-14
            • 1970-01-01
            相关资源
            最近更新 更多