Error while running cucumber in junit
Asked Answered
K

6

5

Hi i am new to cucumber java. i am trying to run a simple cucumber feature test. below are my feature file, step definition file and junit runner file. but i am not able to run the test succesfully in cucumber-java,cucumber-junit 1.1.6 version.

Feature file

Feature: Test if f1 feature is working
Scenario: valid scenario
Given input1 is "t"
When input2 is also "t"
Then result should be "pass"

Stepdefinition file

package cucumberFrameworkPractise;

import org.junit.Assert;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;



public class CucumberStepDefinitionTest {
    String input1,input2,result;
@Given("input1 is \"([^\"]*)\"$")
public void input1(String input1)
{
    this.input1=input1;
}
@When("input2 is also \"([^\"]*)\"$")
public void input2(String input2)
{
    this.input2=input2;
}
@Then("result should be \"([^\"]*)\"$")
public void result(String result)
{
    this.result=result;
    Assert.fail();
}
}

Cucumber runner file

package cucumberFrameworkPractise;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resources/cucumberFrameworkPractise", format = {
        "pretty", "html:target/cucumber-htmlreport",
"json-pretty:target/cucumber-report.json" })
public class CucumberRunner {

}

I am getting below error:

java.lang.NoSuchMethodError: cucumber.runtime.RuntimeOptions.<init>(Ljava/util/List;)V
    at cucumber.runtime.RuntimeOptionsFactory.create(RuntimeOptionsFactory.java:24)
    at cucumber.api.junit.Cucumber.<init>(Cucumber.java:58)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
    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)

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>mrunal</groupId>
  <artifactId>cucumbertest</artifactId>
  <version>1.0</version>
  <build>
  <plugins>
  <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.12.1</version>
        <executions>
          <execution>
            <id>default-test</id>
            <phase>test</phase>
            <goals>
              <goal>test</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
  </plugins>
  </build>
  <dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.0.14</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.0.14</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>1.1.5</version>
    </dependency>
  </dependencies>
</project>

But when i am running with 1.0.14 version of the same i am able to run it successfully. whys is it so? does 1.1.6 version has some bug in it to run? TIA!!!

Karr answered 9/5, 2014 at 7:49 Comment(6)
could you show your pom.xml. Does it work with 1.1.5?Lime
Hi Bala i've tried with 1.1.5 too, but same error.Karr
could you try adding cucumber-core dependency (I am using version 1.1.5) and see if it works. I have had issues not including it although documentation says it is included automatically.Lime
try with 1.1.5 for cucumber-java, cucumber-junit,Lime
Hi Bala still same error it is not working it is failing while trying to create RuntimeOptions runtimeOptions = runtimeOptionsFactory.create(); not sure why is it failing. did what you suggested. any other pointers. i still wonder why is it working in lower version 1.0.14Karr
Try one final thing. Remove Testng dependency but keep junit and see if that works.Lime
K
8

The error means that cucumber.runtime.RuntimeOptions has no constructor which takes a List as argument.

Since all classes are part of cucumber, I suspect a bug in the release. Run mvn dependency:tree and search the output for cucumber. Make sure that you have only a single version of the dependency.

If your classpath is good, try an older version.

If that works, download the sources for cucumber and compile them. Does it work now? If so, open a bug report telling the Cucumber project that the latest release wasn't compile correctly.

Kannry answered 9/5, 2014 at 9:16 Comment(1)
where should i report the bug. I found out the bug. The bug is that in RuntimeOptionsFactory class of cucumber-core jar one import statement is missing for importing RuntimeOptions class. I was just wondering where should i report this bug for cucumber core? TIAKarr
U
9

In Simple term, We need same jar version for cucumber-core,cucumber-java,cucumber-junit. To overcome this issue :)

Error, we are getting because of the jar files and corresponding version(not suitable for our JDK). I played with jar file - now issue is resolved. And also able to run and generate output.

My JDK version- 1.8.0_60 JARS, junit -4.12 cucumber-java-1.2.2.jar cucumber-junit-1.2.2.jar cucumber-core-1.2.2.jar gherkin-2.12.2.jar cucumber-jvm-deps-1.0.3.jar

Note: java,junit,core should be in same version. Remove unwanted cucumber jars. Debug by install only two(Java and Junit) jar files(different version) and try to resolve NoSuchMethod error.

Unstressed answered 13/6, 2016 at 12:54 Comment(1)
This answer might have some truth in it but it's very hard to understand what you are saying. Please try to edit and rephrase your answer.Tannenwald
K
8

The error means that cucumber.runtime.RuntimeOptions has no constructor which takes a List as argument.

Since all classes are part of cucumber, I suspect a bug in the release. Run mvn dependency:tree and search the output for cucumber. Make sure that you have only a single version of the dependency.

If your classpath is good, try an older version.

If that works, download the sources for cucumber and compile them. Does it work now? If so, open a bug report telling the Cucumber project that the latest release wasn't compile correctly.

Kannry answered 9/5, 2014 at 9:16 Comment(1)
where should i report the bug. I found out the bug. The bug is that in RuntimeOptionsFactory class of cucumber-core jar one import statement is missing for importing RuntimeOptions class. I was just wondering where should i report this bug for cucumber core? TIAKarr
A
0

I'm new and still learning. I had a similar 'cucumber runner initialization error' message:

java.lang.NoSuchMethodError: cucumber.runtime.RuntimeOptionsFactory.<init>(Ljava/lang/Class;[Ljava/lang/Class;)V
    at cucumber.api.junit.Cucumber.<init>(Cucumber.java:59)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:87)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:73)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:46)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:522)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)

Referenced Libraries <= My Jars when I was having an error. I then replaced my cucumber-junit-1.1.5.jar with cucumber-junit-1.2.2.jar and the error message is now resolved. I can now run my cucumber junit test. I started with the latest jars but they seems to have issues. I then tried several different combination. I read 'rule of thumb' (also mentioned above) that the three jars (-core, -java and -junit) need to be of same version. Only then I was able to run my feature files and junit tests.

My current working jars are:

gherkin-2.12.2
cucumber-core-1.2.2
cucumber-java-1.2.2
cucumber-junit-1.2.2
cucumber-html-0.2.3
cucumber-jvm-deps-1.0.3
hamcrest-all-1.3
junit-4.11
selenium-server-standalone-3.13.0

I hope this helps.

Advent answered 13/9, 2018 at 15:59 Comment(1)
I can confirm that align all above libs by version resolves the issueBashkir
V
0

Check your dependencies: Cucumber dependencies should be all aligned:

<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-jvm --> 
<dependency>
   <groupId>info.cukes</groupId>
   <artifactId>cucumber-jvm</artifactId>
   <version>1.2.2</version>
   <type>pom</type>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java --> 
<dependency>
   <groupId>info.cukes</groupId>
   <artifactId>cucumber-java</artifactId>
   <version>1.2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-core --> 
<dependency>
   <groupId>info.cukes</groupId>
   <artifactId>cucumber-core</artifactId>
   <version>1.2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit --> 
<dependency>
   <groupId>info.cukes</groupId>
   <artifactId>cucumber-junit</artifactId>
   <version>1.2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-jvm-deps --> 
<dependency>
   <groupId>info.cukes</groupId>
   <artifactId>cucumber-jvm-deps</artifactId>
   <version>1.0.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit --> 
<dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>4.11</version>
</dependency>
Varicotomy answered 26/6, 2019 at 3:12 Comment(0)
P
0

i resolved similar issue by, keeping version of cucumber-junit and cucumber-java same.

Prendergast answered 30/9, 2020 at 17:24 Comment(0)
B
0

gherkin-2.12.2 cucumber-core-1.2.2 cucumber-java-1.2.2 cucumber-junit-1.2.2 cucumber-html-0.2.3 cucumber-jvm-deps-1.0.3 hamcrest-all-1.3 junit-4.11 selenium-server-standalone-3.13.0

this worked for me and No Such method found error get resolved

Batangas answered 22/10, 2020 at 6:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.