1

在 Pester v5 实现中,有什么方法可以使用数据驱动标签?

我的用例:

  • 在更大的数据集上运行
  • 让所有测试都可以在数据集上运行
  • 能够通过配置过滤器针对我的数据集的特定元素运行

我的概念示例:

Describe "Vehicles" {
    Context "Type: <_>" -foreach @("car","truck") {
        # Should be tagged Car for iteration 1, Truck for iteration 2
        It "Should be True" -tag ($_) { $true | should -betrue }
    }
}

TIA

4

1 回答 1

0

你的例子对我有用,所以答案似乎是,是的,你可以这样做。使用示例:

~> Invoke-Pester -Output Detailed
Pester v5.3.1

Starting discovery in 1 files.
Discovery found 2 tests in 12ms.
Running tests.

Running tests from 'C:\Users\wragg\OneDrive\Desktop\so.tests.ps1'
Describing Vehicles
 Context Type: car
   [+] Should be True 18ms (1ms|17ms)
 Context Type: truck
   [+] Should be True 19ms (2ms|16ms)
Tests completed in 129ms
Tests Passed: 2, Failed: 0, Skipped: 0 NotRun: 0


~> Invoke-Pester -Output Detailed -TagFilter car
Pester v5.3.1

Starting discovery in 1 files.
Discovery found 2 tests in 12ms.
Filter 'Tag' set to ('car').
Filters selected 1 tests to run.
Running tests.

Running tests from 'C:\Users\wragg\OneDrive\Desktop\so.tests.ps1'
Describing Vehicles
 Context Type: car
   [+] Should be True 9ms (4ms|5ms)
Tests completed in 66ms
Tests Passed: 1, Failed: 0, Skipped: 0 NotRun: 1


~> Invoke-Pester -Output Detailed -TagFilter truck
Pester v5.3.1

Starting discovery in 1 files.
Discovery found 2 tests in 11ms.
Filter 'Tag' set to ('truck').
Filters selected 1 tests to run.
Running tests.

Running tests from 'C:\Users\wragg\OneDrive\Desktop\so.tests.ps1'
Describing Vehicles
 Context Type: truck
   [+] Should be True 21ms (1ms|19ms)
Tests completed in 97ms
Tests Passed: 1, Failed: 0, Skipped: 0 NotRun: 1
~>
于 2021-11-01T19:01:52.313 回答