我有一个springboot服务,可以使用不同的spring.profiles.active
进行引导。该服务最初是从spring.profiles.active=profile1
开始创建的。然后有人为该服务添加了behave
测试/方案。
稍后,我向服务添加了另一个配置文件,现在我想对两个配置文件运行行为测试。因此,当服务以spring.profiles.active=profile1
启动时,首先运行行为测试,然后以spring.profiles.active=profile2
开始的服务再次运行测试。
我可以运行两次行为测试,并使用环境变量来控制弹簧轮廓设置。我还可以为两个配置文件(如
)标记不同的场景@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|
类似的post提供了类似的解决方案
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|
答案 0 :(得分:0)
我的问题是,有没有办法标记特定示例行?
你真的很亲近。
@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
。
答案 1 :(得分:0)
是的。从行为版本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|