将cucumber-jvm从版本4升级到版本6时是否需要其他上下文配置?

问题描述

我正在使用Cucumber-jvm在Kotlin中执行一些功能测试。

我有标准的空跑者类:

@RunWith(Cucumber::class)
@CucumberOptions(features=[foo],glue=[bar],plugin=[baz],strict=true,monochrome=true)
class Whatever

实际步骤在另一个类中使用@ContextConfiguration springframework批注定义。 此类还使用其他弹簧功能,例如@Autowire或@Qualifier

@ContextConfiguration(locations=["x/y/z/config.xml"])
class MyClass {
    ...
    @Before
    ...

    @Given("some feature file stuff")
    ...

    // etc
}

在黄瓜4.2.0版中,这一切都可以正常工作,但是升级到6.3.0版会导致问题。在更新导入以匹配新的黄瓜项目布局之后,测试现在失败,并显示以下错误:

io.cucumber.core.backend.CucumberBackendException:请使用一些上下文配置来注释胶水类。

它提供了含义的示例...

例如:

    @CucumberContextConfiguration
    @SpringBootTest(classes = TestConfig.class)
    public class CucumberSpringConfiguration {}

或者:

    @CucumberContextConfiguration
    @ContextConfiguration( ... )
    public class CucumberSpringConfiguration {}

似乎在告诉我我可以将@CucumberContextConfiguration添加到MyClass。

但是为什么?

我明白了@CucumberContextConfiguration的意思,here的解释很好,但是当第4版没有它时,为什么我现在需要第6版呢?我看不到任何已被弃用并替换为该功能的功能。

任何帮助将不胜感激:)

解决方法

https://github.com/cucumber/cucumber-jvm/pull/1959删除了上下文配置自动发现。作者得出的结论是,它隐藏了用户错误,将其删除将提供更多的信息并减少复杂性。它还列出了自动应用上下文配置的方案。

请注意,它是在您提到的https://github.com/cucumber/cucumber-jvm/pull/1911之后引入的。

,

由于该错误与我在使用 Spring Boot 运行 Cucumber 测试时遇到的错误完全匹配,所以我正在分享我的修复程序。

可能的原因之一是:Cucumber 找不到 CucumberSpringConfiguration 胶水路径中的类。

解决方案 1:

将 CucumberSpringConfiguration 类移动到胶水路径内(在我的例子中是在步骤包内)。

解决方案 2:

在胶水路径中添加CucumberSpringConfiguration包路径。


下面的屏幕截图描述了我的项目结构。

Project structure

如您所见,我的 CucumberSpringConfig 类位于配置包下,因此当我尝试从命令提示符 (mvn clean test) 运行功能文件时,它向我抛出了错误:

“请使用一些上下文配置来注释粘合类。”

所以我应用了解决方案 2,即在我的 runner 类注释的胶水路径中添加了配置包。

Fix 2

这是CucumberSpringConfiguration类的内容截图:

CucumberSpringConfiguration

只是一个额外的信息:

要从命令提示符运行测试,我们需要在 pom.xml 中包含以下插件 plugin to run test from command prompt

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...