在不同的行为测试中标记不同的示例集
Tag different sets of example in behave test differently
我有一个 spring 启动服务,可以用不同的 spring.profiles.active
启动。该服务最初是从 spring.profiles.active=profile1
开始创建的。然后有人为该服务添加了 behave
test/scenarios。
后来,我向该服务添加了另一个配置文件,现在我想 运行 对两个配置文件进行行为测试。因此,当服务以 spring.profiles.active=profile1
启动时,首先 运行 进行行为测试,然后 运行 再次测试服务以 spring.profiles.active=profile2
.
启动
我可以 运行 执行两次测试并使用环境变量来控制 spring 配置文件设置。我还可以为两个配置文件以不同方式标记我的场景,例如
@profile1
Scenario Outline: test something in profile1
Given: blah
...
@profile2
Scenario Outline: test something in profile2
Given: blah
...
Then run behave tests twice as
>> behave --tags=profile1
>> behave --tags=profile2
但是,两个配置文件中有很多共同的场景,重复具有不同 tags
的场景没有意义。例如,
Scenario Outline: test that a user is recommended at least 10 items
Given a user <userId>
when recommendations are generated
then at least 10 items are returned in the recommendations
Examples:
|userId|
|123456| # I want to use this userId for profile1
|234567| # and this one too for profile1
|987654| # but this one and the following for profile2
|876543|
类似的 提供了类似
的解决方案
Scenario Outline: test that a user is recommended at least 10 items
Given a user <userId>
when recommendations are generated
then at least 10 items are returned in the recommendations
Examples:
|userId|
|123456| # I want to use this userId for profile1
|234567| # and this one too for profile1
Examples:
|userId|
|987654| # but this one and the following for profile2
|876543|
and then use `row2.4` etc to call specific row of examples for the second profile.
然而,这对我来说并不优雅(如果我稍后禁用或重新排列示例怎么办?)。
我的问题是,有没有办法标记特定的示例行?
所以,
Examples: @profile1
|userId|
|123456| # I want to use this userId for profile1
|234567| # and this one too for profile1
Examples: @profile2
|userId|
|987654| # but this one and the following for profile2
|876543|
My question is, is there a way to tag specific example rows?
你们真的很亲密。
@profile1
Examples:
|userId|
|123456| # I want to use this userId for profile1
|234567| # and this one too for profile1
@profile2
Examples:
|userId|
|987654| # but this one and the following for profile2
|876543|
尽管附录对用户数据 implementation 提出了建议,但可能对您的示例场景有用。或者您可能想查看下方的活动标签匹配器 @use.with_profile=profile1
。
是的。从 behave 版本 1.2.6 开始,您可以为每个示例添加标签。
https://behave.readthedocs.io/en/latest/new_and_noteworthy_v1.2.6.html
这是一个例子:
Scenario Outline: test that a user is recommended at least 10 items
Given a user <userId>
when recommendations are generated
then at least 10 items are returned in the recommendations
@profile1
Examples:
|userId|
|123456| # I want to use this userId for profile1
|234567| # and this one too for profile1
@profile2
Examples:
|userId|
|987654| # but this one and the following for profile2
|876543|
我有一个 spring 启动服务,可以用不同的 spring.profiles.active
启动。该服务最初是从 spring.profiles.active=profile1
开始创建的。然后有人为该服务添加了 behave
test/scenarios。
后来,我向该服务添加了另一个配置文件,现在我想 运行 对两个配置文件进行行为测试。因此,当服务以 spring.profiles.active=profile1
启动时,首先 运行 进行行为测试,然后 运行 再次测试服务以 spring.profiles.active=profile2
.
我可以 运行 执行两次测试并使用环境变量来控制 spring 配置文件设置。我还可以为两个配置文件以不同方式标记我的场景,例如
@profile1
Scenario Outline: test something in profile1
Given: blah
...
@profile2
Scenario Outline: test something in profile2
Given: blah
...
Then run behave tests twice as
>> behave --tags=profile1
>> behave --tags=profile2
但是,两个配置文件中有很多共同的场景,重复具有不同 tags
的场景没有意义。例如,
Scenario Outline: test that a user is recommended at least 10 items
Given a user <userId>
when recommendations are generated
then at least 10 items are returned in the recommendations
Examples:
|userId|
|123456| # I want to use this userId for profile1
|234567| # and this one too for profile1
|987654| # but this one and the following for profile2
|876543|
类似的
Scenario Outline: test that a user is recommended at least 10 items
Given a user <userId>
when recommendations are generated
then at least 10 items are returned in the recommendations
Examples:
|userId|
|123456| # I want to use this userId for profile1
|234567| # and this one too for profile1
Examples:
|userId|
|987654| # but this one and the following for profile2
|876543|
and then use `row2.4` etc to call specific row of examples for the second profile.
然而,这对我来说并不优雅(如果我稍后禁用或重新排列示例怎么办?)。
我的问题是,有没有办法标记特定的示例行?
所以,
Examples: @profile1
|userId|
|123456| # I want to use this userId for profile1
|234567| # and this one too for profile1
Examples: @profile2
|userId|
|987654| # but this one and the following for profile2
|876543|
My question is, is there a way to tag specific example rows?
你们真的很亲密。
@profile1
Examples:
|userId|
|123456| # I want to use this userId for profile1
|234567| # and this one too for profile1
@profile2
Examples:
|userId|
|987654| # but this one and the following for profile2
|876543|
尽管附录对用户数据 implementation 提出了建议,但可能对您的示例场景有用。或者您可能想查看下方的活动标签匹配器 @use.with_profile=profile1
。
是的。从 behave 版本 1.2.6 开始,您可以为每个示例添加标签。
https://behave.readthedocs.io/en/latest/new_and_noteworthy_v1.2.6.html
这是一个例子:
Scenario Outline: test that a user is recommended at least 10 items
Given a user <userId>
when recommendations are generated
then at least 10 items are returned in the recommendations
@profile1
Examples:
|userId|
|123456| # I want to use this userId for profile1
|234567| # and this one too for profile1
@profile2
Examples:
|userId|
|987654| # but this one and the following for profile2
|876543|