pesterpester-5

V5 -- Data driven Tags?


In a Pester v5 implementation, any way to have a data driven tag?

My Use Case:

My Conceptual example:

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


Solution

  • Your example works for me, so the answer seems to be, yes you can do that. Usage examples:

    ~> 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
    ~>