如何将多个步骤目录粘合到 Intellij 中的黄瓜测试?
How to glue multiple steps directories to a cucumber test in Intellij?
我有一个 Cucumber 场景,其步骤在多个步骤文件中定义,而不是只有一个。如果我决定 运行 使用 Intellij 进行测试,我会转到 run/debug configurations
菜单,该表单提供了一个名为 glue
的字段,使我能够指定步骤包。
到目前为止,我能够 运行 将所有步骤定义在同一个步骤文件中的场景,但我无法弄清楚如何为需要多个步骤文件的场景执行此操作不同的包。我试过 csv 方法但没有成功。有谁知道我错过了什么?感谢您的帮助。
配置 Cucumber 粘合路径的方法很少。
作为根包中的 cucumber.properties
文件(通常 src/test/resources/cucumber.properties
):
cucumber.glue=com.example.steps1,com.example.steps2
通过命令行
--glue com.example.steps1 --glue com.example.steps2
或使用 @CucumberOptions
注释。
@RunWith(Cucumber.class)
@CucumberOptions(glue ={"com.example.steps1", "com.example.steps2"})
public class RunCucumberTest {
}
使用 IDEA 时,必须用新行或 space(不是逗号!)分隔胶水包。
com.example.steps1
com.example.steps2
如果您使用的是最新版本的 Cucumber (6+),则根本不需要提供胶水。 Cucumber 默认搜索 class 路径。
M.P。 Korstanje 的回答提供了非常有用的提示,但不适用于此特定案例。对我有用的是:
- 在
Glue
字段 中指定父包而不是几个不同的 sub-packages(例如仅使用 com.example
而不是同时使用 com.example.steps1, com.example.steps2
)
- Select
Use classpath of module
字段中的正确模块。
我有一个 Cucumber 场景,其步骤在多个步骤文件中定义,而不是只有一个。如果我决定 运行 使用 Intellij 进行测试,我会转到 run/debug configurations
菜单,该表单提供了一个名为 glue
的字段,使我能够指定步骤包。
到目前为止,我能够 运行 将所有步骤定义在同一个步骤文件中的场景,但我无法弄清楚如何为需要多个步骤文件的场景执行此操作不同的包。我试过 csv 方法但没有成功。有谁知道我错过了什么?感谢您的帮助。
配置 Cucumber 粘合路径的方法很少。
作为根包中的 cucumber.properties
文件(通常 src/test/resources/cucumber.properties
):
cucumber.glue=com.example.steps1,com.example.steps2
通过命令行
--glue com.example.steps1 --glue com.example.steps2
或使用 @CucumberOptions
注释。
@RunWith(Cucumber.class)
@CucumberOptions(glue ={"com.example.steps1", "com.example.steps2"})
public class RunCucumberTest {
}
使用 IDEA 时,必须用新行或 space(不是逗号!)分隔胶水包。
com.example.steps1
com.example.steps2
如果您使用的是最新版本的 Cucumber (6+),则根本不需要提供胶水。 Cucumber 默认搜索 class 路径。
M.P。 Korstanje 的回答提供了非常有用的提示,但不适用于此特定案例。对我有用的是:
- 在
Glue
字段 中指定父包而不是几个不同的 sub-packages(例如仅使用 - Select
Use classpath of module
字段中的正确模块。
com.example
而不是同时使用 com.example.steps1, com.example.steps2
)