Skip to content
Advertisement

Error when running springboot with Cucmber and Serenity

I am trying to test my spring boot application using serenity-cucumber.

To do this , I have my entry point:

package integration.com.foo.proj;

import io.cucumber.junit.CucumberOptions;
import net.serenitybdd.cucumber.CucumberWithSerenity;
import org.junit.runner.RunWith;

@RunWith(CucumberWithSerenity.class)
@CucumberOptions(features = "src/test/resources")
public class CucumberIntegrationTest {
}

Then my Baseclass to be used by step defs,

package integration.com.foo.proj;

import com.foo.proj.Application;
import io.cucumber.spring.CucumberContextConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

@CucumberContextConfiguration
@SpringBootTest(classes = Application.class)
@ActiveProfiles("sit")
public class SpringIntegrationTest {


}

And , one of my step defs is running some dummy tests at this point to work as glue.

package integration.com.foo.proj;

import io.cucumber.java.en.And;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import org.springframework.beans.factory.annotation.Value;

public class StepDefs extends SpringIntegrationTest {

  @Value("${config.value}")
  private String configValue;

  @When("^the client calls /version$")
  public void the_client_issues_GET_version() throws Throwable {
    String s = configValue;
  }
  @Then("^the client receives status code of (\d+)$")
  public void the_client_receives_status_code_of(int statusCode) throws Throwable {
    String s = configValue;
  }
  @And("^the client receives server version (.+)$")
  public void the_client_receives_server_version_body(String version) throws Throwable {
    String s = configValue;
  }
}

My feature class:

Feature: the version can be retrieved
        Scenario: client makes call to GET /version
            When the client calls /version
            Then the client receives status code of 200
            And the client receives server version 1.0

I have imported the following dependencies, (have also tried with testCompile):

testImplementation 'io.cucumber:cucumber-java:6.10.4'
testImplementation 'io.cucumber:cucumber-junit:6.10.4'
testImplementation 'io.cucumber:cucumber-spring:6.10.4'

testImplementation 'net.serenity-bdd:serenity-core:2.4.49'
testImplementation 'net.serenity-bdd:serenity-spring:2.4.49'
testImplementation 'net.serenity-bdd:serenity-junit:2.4.49'
testImplementation 'net.serenity-bdd:serenity-cucumber5:2.2.6'

When I am running the test , getting following error.

Exception in thread "main" java.lang.NoSuchMethodError: io.cucumber.core.options.CommandlineOptionsParser: method <init>()V not found
    at net.serenitybdd.cucumber.cli.Main.run(Main.java:24)
    at net.serenitybdd.cucumber.cli.Main.main(Main.java:19)

During initial search , came across this post whic mentioned to import cucumber-java and cucumber-junit in one of the answers , but does not work.

Is this due to the depency?

I also followed the post from serenity-bdd, but unable to get this working.
Getting started with Cucumber and Serenity
Integration testing Spring

Advertisement

Answer

I would normally not answer my own question , but I see few similar questions on SO.

For my case, removing fixed the issue.
testCompile (“io.cucumber:cucumber-spring:6.10.4”)

However, to get the correct version of dependencies, if you are stuck in such issue, is to refer there github and check release notes and dependency tee.

For my case, the issue was on Cucumber-Serenity5.

So getting the dependecncies from build.gradle, worked. https://github.com/serenity-bdd/serenity-cucumber5/blob/master/build.gradle

Please note, the actual versions are defined in, gradle.proporties.
https://github.com/serenity-bdd/serenity-cucumber5/blob/master/gradle.properties

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement