python - 在行为测试中标记不同的示例集
问题描述
我有一个 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|
类似的帖子提供了一个解决方案,例如
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|
解决方案
我的问题是,有没有办法标记特定的示例行?
你真的很亲近。
@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|
尽管附录对用户数据实现提出了建议,但可能对您的示例场景有用。或者您可能想查看@use.with_profile=profile1
下面的活动标签匹配器。
推荐阅读
- javascript - 当您在 NodeJS 中定义一个函数时,该函数是哪个对象的成员?
- c++ - Winsock2:当我尝试发送带空格的字符串时,该函数遇到空格时出现停止发送
- vue.js - Vuejs - 我可以在我的全局 router.beforeEach 中使用导入的函数吗
- c++ - 根据枚举参数调用专门的模板方法
- html - Button not going underneath header
- rollup - Rollup - 保留模块 + css
- c++ - SDL2 无法捕获控制台键盘事件?
- microsoft-graph-api - Get contacts by IDs in batch in Microsoft Graph
- r - ggplot - plot an average of categories on the x-axis in R
- netlogo - How to select the last n items from a list in Netlogo