gpt4 book ai didi

karate - 有没有办法针对预启动的 spring boot 服务器将 Karate 测试作为集成测试套件运行?

转载 作者:行者123 更新时间:2023-12-05 07:16:48 26 4
gpt4 key购买 nike

在 Maven 构建的“集成测试”阶段,是否有任何好的方法让 Karate 测试来测试 Spring-Boot 微服务?我的意思是:是否存在有效的反模式/解决方法,或者我是否运气不好,因为这是 Karate 开发的事后想法?

到目前为止我收集到的事实:

  1. 它在这里说:“surefire 插件没有硬编码到 Karate 中” Is there a way to run Karate test during maven's integration test phase?

  2. 在 maven-failsafe-plugin 上下文中运行 Karate 测试根本不起作用。很容易在下面的我的测试项目 url 上重现。两个最重要的问题:

    1. 从 maven-failsafe 运行时,Karate 将生成 .txt 和 .html 文件,但不会生成 .json Cucumber 输出文件。
    2. 因此,您无法从 cucumber-reporting 插件(我需要)获得 HTML 报告
  3. 我创建了一个项目来证明这些事实:https://github.com/djangofan/karate-api-sample

  4. 运行集成测试要求我在测试套件之前启动 Spring Boot,然后停止 Spring Boot 服务器。 Maven SureFire 没有此功能,但 maven failsafe 插件有:maven build helper 插件有一个预集成测试 Hook 。仅受 Maven surefire 限制,我运气不好。

  5. 我在 karate/karate-demo 项目中看到一个从代码启动 spring boot 服务器的示例。当我尝试测试已经建立的 Web 服务时,这并不容易完成。这是我唯一的选择吗:将 surefire 与类过滤器和代码一起使用以进行引导?

  6. 如果没有好的答案,我将恢复使用 cucumber-java + resteasy,我很确定它可以与 maven failsafe 一起使用:https://maven.apache.org/surefire/maven-failsafe-plugin/examples/cucumber.html

最佳答案

首先,这不是 Karate.js 不知道它来自哪里:)

When running from maven-failsafe, Karate will generate .txt and .html files but does not generate .json Cucumber output files.

抱歉,无法复制。

对于故障保护,只需使用命名约定即可,例如**/IT*.java

Maven SureFire does not have this capability BUT the maven failsafe plugin does:

所以使用上面提到的故障保护。如果您无法做到这一点,请更改您的项目以证明该问题,我们 promise 会修复它。另请参阅这些说明:https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Given no good answer, I will just revert to using cucumber-java + resteasy

那当然是你的选择。至少在我(有偏见的 :) 看来你会 miss all the JSON assertion value that Karate adds ,以及报告的并行执行+聚合。我相信您会尽可能提供帮助,以便我们可以为所有需要此解决方案的人提供更好的体验 - 但是,嘿 - 不用担心 :P

关于karate - 有没有办法针对预启动的 spring boot 服务器将 Karate 测试作为集成测试套件运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59082487/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com