10

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

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

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

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


Output when running CukesRunner.java as 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/

5
  • Where do you have your stepdefs? Commented Feb 15, 2014 at 8:26
  • @Bala Where should it be? Commented Feb 18, 2014 at 20:29
  • 1
    check this answer. It might help you. stackoverflow.com/questions/21753267/… Commented Feb 19, 2014 at 9:15
  • I have the same problem so I am bumping. I infer from the stack trace that you are running the test in Eclipse. I am editing the question to reflect my experience, which is that is works if you "Run as... -> Maven test" Commented May 1, 2014 at 13:53
  • @Onizuka, Did you ever manage to resolve this issue? Commented Nov 11, 2014 at 8:38

9 Answers 9

22

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

    <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>
Sign up to request clarification or add additional context in comments.

Comments

4

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

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

Comments

2

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

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

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

1 Comment

That's what resolved my issue i.e. getting rid of junit-dep
1
<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>

1 Comment

I have updated my POM as below, and it gets resolved.
0

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.

Comments

0

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

Comments

0

Make sure you use the correct JUnit version in your POM.xml. Change it to latest from 4.10 to 4.11 it works.

Comments

0

The error you’re seeing is due to a mismatch between the version of JUnit that Cucumber expects and the version that is actually on your classpath. It could also be some dependency using old functionality that creates the mismatch. More on that below.

The method org.junit.runner.Description.createSuiteDescription(String, Serializable, Annotation[]) was added in JUnit 4.12, but you’re using JUnit 4.8.2.

Try updating the version of JUnit in your pom.xml file to 4.12 or higher.

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

change, re-import Maven dependencies in Eclipse (Right click on the project -> Maven -> Update Project), and then try running your tests again. That should help resolve the particular general NoSuchMethodError

What I had to ressolve was a clash of dependencies. I am using a customized test automation framework afor.co.nz. I run the framework in bitbucket pipeline. I had 15 dependencies in my pom.xml. I had to uncomment one by one until i found the library causing the issue. a 2012 dependency json-simple 1.1.1

error I got with json-simple 1.1.1

[INFO] Surefire report directory: /opt/atlassian/pipelines/agent/build/target/surefire-reports
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running RunTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.547 sec <<< FAILURE!
RunTest  Time elapsed: 0.546 sec  <<< ERROR!
java.lang.NoSuchMethodError: 'org.junit.runner.Description org.junit.runner.Description.createSuiteDescription(java.lang.String, java.io.Serializable, java.lang.annotation.Annotation[])'
    at io.cucumber.junit.FeatureRunner.getDescription(FeatureRunner.java:118)
    at io.cucumber.junit.Cucumber.describeChild(Cucumber.java:191)
    at io.cucumber.junit.Cucumber.describeChild(Cucumber.java:89)
    at org.junit.runners.ParentRunner.getDescription(ParentRunner.java:290)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:296)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Results :
Tests in error: 
  RunTest: 'org.junit.runner.Description org.junit.runner.Description.createSuiteDescription(java.lang.String, java.io.Serializable, java.lang.annotation.Annotation[])'

after commenting dependency json-simple 1.1.1

[INFO] Surefire report directory: /opt/atlassian/pipelines/agent/build/target/surefire-reports
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running RunTest
SLF4J(I): Connected with provider of type [org.apache.logging.slf4j.SLF4JServiceProvider]
Logging host stats to the preferred location
@loginO9
Scenario: login with valid credentials     # src/test/resources/features/web/O9Login.feature:5
Starting scenario: login with valid credentials

Comments

-1

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.

1 Comment

Why not version 4.12?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.