java - 使用 Cucumber 和 Serenity 运行 springboot 时出错
问题描述
我正在尝试使用 serenity-cucumber 测试我的 Spring Boot 应用程序。
为此,我有我的切入点:
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;
}
}
我的特征类:
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-java
,并且cucumber-junit
在其中一个答案中,但不起作用。
这是因为依赖吗?
我也关注了 serenity-bdd 的帖子,但无法使其正常工作。
开始使用 Cucumber 和 Serenity
集成测试 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
推荐阅读
- c# - wpf datagrid 单元格编辑错误:(TwoWay 或 OneWayToSource 绑定无法在只读属性上工作)
- python - 要求抽象类的子类不覆盖方法
- bash - MV 命令行不适用于某些文件(OSX)
- html - 在表格中动态添加行/列时,如何保持容器大小?
- java - 在春天将值从控制器传递到html
- twilio - 如何将按键发送到数字接收
- magento - 来自 CLI 的 Magento 1.14.2.1 到 Magento 2.3.2
- javascript - 如何通过jQuery在同一行中的另一个输入ID选择第n个输入文本框?
- ios - Ionic 4 - 目标为“_blank”的 InAppBrowser 在 IOS 上不起作用?
- r - 拆分数据框值并在 R 中放入一个组?