1

我有一个具有不同场景的功能文件。为每个功能文件添加多个标签是个好主意吗?

Feature: Login.

@daily @chrome @admin @smoketest 

Scenario 1

Scenario 2

Scenario 3

我能否一次使用任何一个或多个标签使用命令行执行测试?

4

1 回答 1

3

是的,一个特征文件中有多个标签是一个常见的用例。您使用标签对测试进行分类。您可以通过将标签放置在正确的位置来构建您的功能文件以运行您想要的所有测试,而不是一次运行多个标签/类别。

这里有两个例子:

  • 示例 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 测试是一个肤浅但快速的测试,而每周测试是最彻底的测试,因为它运行了所有场景。

  • 示例 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 标记。

于 2019-04-11T18:47:32.113 回答