java - 如何在功能文件中仅在后台运行一次 java 类

标签 java karate

我在功能文件的背景中有一个声明,

def token = Java.type("Calling a static method from a java class")

我的功能文件中有 4 个场景,这个 java 类被调用了 4 次。如何只调用这个java类一次?

最佳答案

根据 Karate 文档,您必须使用callonce

Variables set using def in the Background will be re-set before every Scenario. If you are looking for a way to do something only once per Feature, take a look at callonce. On the other hand, if you are expecting a variable in the Background to be modified by one Scenario so that later ones can see the updated value - that is not how you should think of them, and you should combine your 'flow' into one scenario. Keep in mind that you should be able to comment-out a Scenario or skip some via tags without impacting any others. Note that the parallel runner will run Scenario-s in parallel, which means they can run in any order.

请检查

关于java - 如何在功能文件中仅在后台运行一次 java 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56701871/

相关文章:

java - 如何在Maven中更新子模块的版本?

java - 任务 ':app:mergeDebugResources' 执行失败。错误: invalid dimen

java - textview不显示文本

java - 我无法在代码中实例化 Integer 类的对象 (Java)

spring-boot - 在运行 Karate 测试之前运行位于另一个项目上的 Spring Boot 应用程序?

karate - 响应中的 JSON 数组被转换为 JSON 对象

java - 如何使用 Gradle 运行 Jetty

gradle - testTags() 测试方法在我的 gradle 项目中未被识别为测试,使用 junit5

'mvn gatling:test' 命令未拾取 Karate argLine 参数

karate - 在 Karate 中,我们如何与 BA 协作来自动化业务场景