1

I am new to Java and new to cucumber as well. I was trying to setup the cucumber testing framework using maven but getting an exception while running the cucumber tests.

I have in my pom.xml dependencies set as :

<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.1.5</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.1.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-picocontainer</artifactId>
        <version>1.1.2</version>
    </dependency>
</dependencies>

The feature file has the following entries:

package cucumber.demo;

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

public class Steps {

    @Given("^This is my first dummy step$")
    public void This_is_my_first_dummy_step() throws Throwable {
        System.out.println("Excuted the first given step.");
    }

    @When("^This is my second dummy step$")
    public void This_is_my_second_dummy_step() throws Throwable {
        System.out.println("Exceuted 2nd step.");
    }

    @Then("^This is my third dummy step$")
    public void This_is_my_third_dummy_step() throws Throwable {
        System.out.println("Excuted the third step.");
    }

}

My RunnerTest.java has the following code:

package cucumber.demo;

import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@Cucumber.Options(
        features= {"html:target/cucumber-html-report", "json:target/cucumber-json-report.json"}
        )


public class RunnerTest {

}

When I run the application, I get the following error message:

Test set: cucumber.demo.RunnerTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.039 sec <<< FAILURE!
initializationError(cucumber.demo.RunnerTest)  Time elapsed: 0.005 sec  <<< ERROR!
java.lang.NoSuchMethodError: cucumber.runtime.RuntimeOptions.<init>(Ljava/util/Properties;[Ljava/lang/String;)V
    at cucumber.runtime.junit.RuntimeOptionsFactory.create(RuntimeOptionsFactory.java:32)
    at cucumber.api.junit.Cucumber.<init>(Cucumber.java:56)
    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.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:51)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)

Any idea why I am receiving this message. Let me know more details are needed. Thanks, Anirban

troig
  • 7,072
  • 4
  • 37
  • 63
Anirban
  • 589
  • 3
  • 16
  • 40

3 Answers3

1

As far as I know you should use the same version for the 3 different cucumber* jars. Form what I can tell cucumber-java is 1.1.5 and cucumber jars ares 1.1.2 for the other 2.

Also there are newer versions to try.

http://mvnrepository.com/artifact/info.cukes/cucumber-java/1.2.2 (check the deps part at the bottom)

Oren Efron
  • 409
  • 5
  • 8
1

Check maven pom.xml cucumber-core cucumber-java cucumber-junit

These files should have the same version. In your example cucumber-java artifact id has different version than the rest. Change it

Veronica
  • 11
  • 1
0

Maybe I'm wrong but based in your @Cucumber.Options annotation, I supose you want to create two test reports (one in html format and other in json format). So, you have to use format instead features in the annotation:

@RunWith(Cucumber.class)
@Cucumber.Options(
      format = {"html:target/cucumber-html-report", "json:target/cucumber-json-report.json"}
)

Hope it helps

troig
  • 7,072
  • 4
  • 37
  • 63
  • 2
    Correct. Also you are mixing jars from different versions of Cucumber - 1.1.5 for cucumber-java and 1.1.2 for cucumber-picocontainer & cucumber-junit You should use jars that all have the same version number. – Seb Rose Oct 15 '14 at 22:39