Cucumber JUnit runner Java lang.NoSuchMethodError:

Try to do some automated testing JUnit test I created two files and edited the pom.exe that came with the Maven project XML to add dependencies The contents are as follows The first of the two files is cucumber Feature file, which is a simple language cucumber The other is cukesrunner java

When I run my test using project – > run – > Maven test with..., it works as expected

However, when I use the eclipse JUnit GUI to run cukesrunner Java file, error occurred:

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

Run cukesrunner Java as JUnit test output:

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 do I build my project in Eclipse: http://postimg.org/image/vf6tlw7el/full/

Solution

Update your JUnit version. Maybe your surefire plug-in will solve this problem

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

To be sure:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.16</version>
        </plugin>
    </plugins>
</build>
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>