在一个特征文件中添加多个标签
Adding multiple tags in one feature file
我有一个包含不同场景的功能文件。为每个功能文件添加多个标签是个好主意吗?
Feature: Login.
@daily @chrome @admin @smoketest
Scenario 1
Scenario 2
Scenario 3
我能否一次使用一个或多个标签使用命令行执行测试?
是的,在一个功能文件中有多个标签是一个常见的用例。您使用标签对测试进行分类。不是一次 运行 多个 tags/categories,您可以通过将标签放在正确的位置 运行 将您想要的所有测试构建为 运行。
这里有两个例子:
- 示例 1:您有一个带有示例的功能(场景大纲)。每次有人提交 (@ci) 时,都应该测试该功能的最常见的快乐路径。不太常见的快乐路径应该每天测试 (@daily),罕见的路径可以每周测试 (@weekly)。
Feature: Buy the product
The product can be bought.
Scenario Outline: A customer buys the product
Given product <Product>
And payment method <PaymentMethod>
When customer clicks buy
Then product ends up in basket
@ci @daily @weekly
Examples:
| Product | PaymentMethod |
| Book | Cash |
@daily @weekly
Examples:
| Product | PaymentMethod |
| Software | Visa |
| Music | MasterCard |
@weekly
Examples:
| Product | PaymentMethod |
| Watch | DinersClub |
| Hitman | BitCoin |
我现在可以将 CI/CD 工具设置为 运行
dotnet test --filter TestCategory=ci
每次有人提交。我可以安排这个
dotnet test --filter TestCategory=daily
到 运行 每天一次。最后我可以将其设置为每周 运行:
dotnet test --filter TestCategory=weekly
请注意,每日类别还将 运行 ci 测试,而每周类别将 运行 所有测试,因为标签也在那里。因此,ci 测试是一个超级ci但速度很快的测试,而每周测试是最彻底的测试,因为它运行涵盖了所有场景。
- 示例 2:您有一个功能可以满足多个要求。有些场景可以同时测试多个需求。
Feature: Start and stop engine
The engine has a start/stop mechanism that can be triggered by software.
@req123 @req124
Scenario: Start engine
Given engine is stopped
When operator clicks on start button
Then engine starts
@req123 @req124
Scenario: Stop engine
Given engine is started
When operator clicks on stop button
Then engine starts
@req123
Scenario: Start engine
Given engine is stopped
When operator clicks on stop button
Then nothing happens
如果我们想证明需求 123,我们会 运行:
dotnet test --filter TestCategory=req123
所有场景都会 运行。如果我们想证明要求 124,我们会 运行
dotnet test --filter TestCategory=req124
前两个场景 运行。最后一个将被跳过,因为它没有用 req124 标记。
我有一个包含不同场景的功能文件。为每个功能文件添加多个标签是个好主意吗?
Feature: Login.
@daily @chrome @admin @smoketest
Scenario 1
Scenario 2
Scenario 3
我能否一次使用一个或多个标签使用命令行执行测试?
是的,在一个功能文件中有多个标签是一个常见的用例。您使用标签对测试进行分类。不是一次 运行 多个 tags/categories,您可以通过将标签放在正确的位置 运行 将您想要的所有测试构建为 运行。
这里有两个例子:
- 示例 1:您有一个带有示例的功能(场景大纲)。每次有人提交 (@ci) 时,都应该测试该功能的最常见的快乐路径。不太常见的快乐路径应该每天测试 (@daily),罕见的路径可以每周测试 (@weekly)。
Feature: Buy the product
The product can be bought.
Scenario Outline: A customer buys the product
Given product <Product>
And payment method <PaymentMethod>
When customer clicks buy
Then product ends up in basket
@ci @daily @weekly
Examples:
| Product | PaymentMethod |
| Book | Cash |
@daily @weekly
Examples:
| Product | PaymentMethod |
| Software | Visa |
| Music | MasterCard |
@weekly
Examples:
| Product | PaymentMethod |
| Watch | DinersClub |
| Hitman | BitCoin |
我现在可以将 CI/CD 工具设置为 运行
dotnet test --filter TestCategory=ci
每次有人提交。我可以安排这个
dotnet test --filter TestCategory=daily
到 运行 每天一次。最后我可以将其设置为每周 运行:
dotnet test --filter TestCategory=weekly
请注意,每日类别还将 运行 ci 测试,而每周类别将 运行 所有测试,因为标签也在那里。因此,ci 测试是一个超级ci但速度很快的测试,而每周测试是最彻底的测试,因为它运行涵盖了所有场景。
- 示例 2:您有一个功能可以满足多个要求。有些场景可以同时测试多个需求。
Feature: Start and stop engine
The engine has a start/stop mechanism that can be triggered by software.
@req123 @req124
Scenario: Start engine
Given engine is stopped
When operator clicks on start button
Then engine starts
@req123 @req124
Scenario: Stop engine
Given engine is started
When operator clicks on stop button
Then engine starts
@req123
Scenario: Start engine
Given engine is stopped
When operator clicks on stop button
Then nothing happens
如果我们想证明需求 123,我们会 运行:
dotnet test --filter TestCategory=req123
所有场景都会 运行。如果我们想证明要求 124,我们会 运行
dotnet test --filter TestCategory=req124
前两个场景 运行。最后一个将被跳过,因为它没有用 req124 标记。