运行 使用 Cucumber 和 Serenity 进行春季启动时出错

Error when running springboot with Cucmber and Serenity

我正在尝试使用 serenity-cucumber 测试我的 spring 启动应用程序。

为此,我有我的切入点:

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 {
}

然后我的Baseclass将被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 {


}

而且,我的步骤定义之一是 运行 一些虚拟测试在这一点上起到胶水的作用。

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;
  }
}

我的特色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

我已经导入了以下依赖项,(也尝试过 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'

当我 运行 测试时,出现以下错误。

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)

在最初的搜索过程中,遇到了这个 post,其中一个答案提到要导入 cucumber-javacucumber-junit,但没有用。

这是因为依赖吗?

我也遵循了 serenity-bdd 的 post,但无法正常工作。
Getting started with Cucumber and Serenity
Integration testing Spring

我通常不会回答我自己的问题,但我在 SO 上看到很少有类似的问题。

就我而言,删除解决了问题。
testCompile ("io.cucumber:cucumber-spring:6.10.4")

但是,要获得正确版本的依赖项,如果您遇到此类问题,请参阅此处 github 并检查发行说明和依赖项 tee。

就我而言,问题出在 Cucumber-Serenity5

因此,从 build.gradle 获取依赖项成功了。 https://github.com/serenity-bdd/serenity-cucumber5/blob/master/build.gradle

请注意,实际版本在 gradle.proporties.
中定义 https://github.com/serenity-bdd/serenity-cucumber5/blob/master/gradle.properties