当前位置: 首页 > 知识库问答 >
问题:

CucumberBackendException:无测试实例

武晨
2023-03-14

我有一个Spring Boot 2.7.1(但与2.6.4相同)项目使用Cucumber BOM 7.4.1。

    testImplementation(platform("io.cucumber:cucumber-bom:7.4.1"))
    testImplementation group: 'io.cucumber', name: 'cucumber-java8'
    testImplementation group: 'io.cucumber', name: 'cucumber-spring'
    testImplementation group: 'io.cucumber', name: 'cucumber-junit-platform-engine'

我的切入点是:

@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features")
@ConfigurationParameters({
    @ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "my.project.cucumber"),
    @ConfigurationParameter(key = FILTER_TAGS_PROPERTY_NAME, value = "@Dwh"),
    @ConfigurationParameter(key = JUNIT_PLATFORM_NAMING_STRATEGY_PROPERTY_NAME, value = "long"),
    @ConfigurationParameter(key = PLUGIN_PUBLISH_QUIET_PROPERTY_NAME, value = "true"),
    @ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "json:build/cucumber/cucumber.json")
})
public class RunCucumberDwhTest {

}

我的胶水代码:

@SpringBootTest(classes = DwhE2EApplication.class, webEnvironment = RANDOM_PORT)
@ContextConfiguration(classes = DwhE2EApplication.class)
@CucumberContextConfiguration
@ActiveProfiles("test")
public class DwhStepDef implements En {

  ....
}

运行Cucumber测试时,我遇到了以下错误:

我可以在日志中看到我的Spring上下文被加载,内存中的DB被引导。。。之后失败。

在调试模式下,我看到给定/何时/然后步骤被捕获,因此可以肯定地找到我的功能文件

实际上,当Cucumber在执行步骤后执行一些清理时,它似乎失败了:

在io中的某个点。cucumberSpringTestContextAdapter,我们有一个被调用的方法:

private void notifyTestContextManagerAboutAfterTestMethod() {
    try {
        Object delegateTestInstance = delegate.getTestContext().getTestInstance();
        Method dummyMethod = TestContextAdaptor.class.getMethod("cucumberDoesNotHaveASingleTestMethod");
        delegate.afterTestMethod(delegateTestInstance, dummyMethod, null);
    } catch (Exception e) {
        throw new CucumberBackendException(e.getMessage(), e);
    }
}

这是代表。getTestContext()。getTestInstance()引发异常,因为testInstance为null。

知道为什么会这样吗?

共有1个答案

黄修永
2023-03-14

在调试模式下进行了一些调查后,我终于明白了。我相信这是7.4.1cucumber版本带来的变化,因为它在以前的版本中没有发生。我在这里报告了它:https://github.com/cucumber/cucumber-jvm/issues/2584

基本上,我的胶水代码在实例化时抛出异常。但是Cucumber没有捕获异常,而是记录了一条完全不相关的错误消息。

当我意识到我没有在glue code类中输入为步骤定义的代码时,我明白了这一点。然后,我意识到我正在进入粘合代码构造函数,但从那里引发了一个异常。这个例外被cucumber悄悄吞下,这让我在错误的方向上走了比预期更长的时间。

 类似资料:
  • 我已经使用testcontainers创建了一个Postgres实例。容器启动了,但我无法访问它。 我已经尝试使用DBeaver在容器化数据库中连接。在eclipse控制台中,一切似乎都很好: 01:29:34.662[主]调试com。github。多克雅娃。果心命令AbstrDockerCmd-Cmd:com。github。多克雅娃。果心命令CreateContainerCmdImpl@7338

  • 自我介绍 项目介绍和担当职位 开发经验有无? 为什么选择测试 如何测试文字中是否含有手机号(没答上) 举例http响应状态码和功能 linux常用十个指令 vi编辑器有何指令 微信红包用例 数据库的查看和修改 查看任务进程 python的学习程度 都是根据简历写的问的 面试官挺nice #我的实习日记#

  • 当试图用包含所有上下文配置的抽象类运行stepdefs时,spring看到2个不同的beans parent和step def 我使用的是Spring Booking版本:2.6.4,JUnit 5和Cucumber版本7.2.3 异常堆栈跟踪: io.cucumber.core.runtime.CucumberExecutionContext.runTestCase:没有可用的“Cucumber

  • 第一家创业型公司(几百人) 面备选实习生?(一面) 1. 微信聊天界面测试 2.数据库语句,查询去重 第二家国内某北斗(一面) 0.如何进行一个页面测试 1.购物查询怎么测 2.开发不认bug 3.测试条件模糊怎么办 4.与其他竞争者有什么优势 5.接口测试会不会 反问 1.大概什么时候收到面试结果 2.主要是自动化测试还是功能测试 3.还有什么能提升的地方(答:接口测试) #实习生应该准时下班吗

  • 拿开发简历投的测试 总共50分钟 面试开始面试官先介绍了一下业务,大概有十分钟,谈到可能进公司要转go或者python 问了一些计网(DNS,子网掩码,网关)和linux 简历上的东西都没咋问😰 最后coding,给一段测试的日志,输出要求的内容,无算法

  • 本文向大家介绍SpringSecurity 测试实战,包括了SpringSecurity 测试实战的使用技巧和注意事项,需要的朋友参考一下 引言 试题管理系统的安全模块使用Spring Security,代码从原华软仓库移植,在移植的过程中,发现原测试编写的不好,遂在新系统中对安全模块测试进行了重构。 Spring 测试 添加@SpringBootTest注解,意为这是一个基于SpringBoot