黄瓜junit runner java.lang.NoSuchMethodError:

时间:2014-02-12 20:09:27

标签: java maven junit cucumber cucumber-jvm

尝试实施黄瓜进行一些自动化测试。 jUnit测试。我创建了2个文件并编辑了maven项目附带的pom.xml来添加依赖项。内容如下所示。两个文件中的第一个是黄瓜.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


CukesRunner.java作为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)


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

8 个答案:

答案 0 :(得分:15)

更新你的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>

答案 1 :(得分:1)

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

问题是由junit:junit-dep:4.10库造成的,“又名”......

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

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

答案 2 :(得分:1)

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

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

答案 3 :(得分:0)

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

答案 4 :(得分:0)

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

答案 5 :(得分:0)

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

答案 6 :(得分:0)

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

答案 7 :(得分:-1)

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