使用Cucmber和Serenity运行springboot时出错



我正在尝试使用宁静黄瓜测试我的春季启动应用程序。

要做到这一点,我有我的入口点:

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

然后我的基类将被步骤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 {

}

而且,我的一个步骤defs在这一点上运行一些虚拟测试,以起到粘合的作用。

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

我的功能类:

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)

在最初的搜索过程中,发现了这篇文章,其中一个答案中提到导入cucumber-javacucumber-junit,但不起作用。

这是因为depency吗?

我也关注了来自宁静bdd的帖子,但无法做到这一点
Cucumber和Serenity入门
集成测试Spring

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

就我而言,删除解决了这个问题
testCompile("io.黄瓜:黄瓜春季:6.10.4"(

然而,如果您遇到这样的问题,要获得正确版本的依赖项,需要参考github并检查发行说明和依赖项tee。

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

因此,从build.gradle获得依赖关系是有效的。https://github.com/serenity-bdd/serenity-cucumber5/blob/master/build.gradle

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