考虑有 100 个场景,我想在 prod 环境中运行 99 个场景,在 stage 环境中运行 100 个场景。
空手道有办法实现这一目标吗?
我尝试过的事情 1. 创建一个包含 1 个场景的功能文件和另一个包含剩余 99 个场景的功能文件 2. 将标签添加到 1 个场景文件 3. 运行时忽略它
但是当我在詹金斯工作中使用它时,我必须运行一个命令才能在两台机器上运行,所以不起作用
用@hundred标记第100个场景,当你想运行99个场景时只需运行以下命令
mvn test -Dkarate.options="--tags ~@hundred"
Run Code Online (Sandbox Code Playgroud)
mvn test当您想要运行所有测试时只需运行即可。
您可以标记场景
@hundred
Scenario: the scenario only played in one case
Given <...>
Run Code Online (Sandbox Code Playgroud)
但您也可以标记功能
@hundred
Feature: The feature containing the scenario only played in one case
Background:
* <..>
Scenario: <...>
Run Code Online (Sandbox Code Playgroud)
在回答后编辑:您可以使用第二个运行时变量:
mvn test -Dkarate.options="--tags ~@{variable2}" -Dkarate.env={variable}
Run Code Online (Sandbox Code Playgroud)
或者甚至使用相同的运行时变量:
mvn test -Dkarate.options="--tags ~@{variable}" -Dkarate.env={variable}
Run Code Online (Sandbox Code Playgroud)
这可能不是最好的解决方案,但您可以将 @Prod 添加到 99 个场景,将 @Stage 添加到所有场景,然后将命令切换为:
mvn test -Dkarate.options="--tags @{variable}" -Dkarate.env={variable}
Run Code Online (Sandbox Code Playgroud)
这样做的时间有点长,但至少每个功能/场景上的标签将对应于它们启动的情况