|
38 | 38 | commenting out a test, because the test remains listed in the output. Use the Strict parameter |
39 | 39 | of Invoke-Pester to force all skipped tests to fail. |
40 | 40 |
|
41 | | - .PARAMETER TestCases |
42 | | - Optional array of hashtable (or any IDictionary) objects. If this parameter is used, |
43 | | - Pester will call the test script block once for each table in the TestCases array, |
44 | | - splatting the dictionary to the test script block as input. If you want the name of |
45 | | - the test to appear differently for each test case, you can embed tokens into the Name |
| 41 | + .PARAMETER ForEach |
| 42 | + (Formerly called TestCases.) Optional array of hashtable (or any IDictionary) objects. |
| 43 | + If this parameter is used, Pester will call the test script block once for each table in |
| 44 | + the ForEach array, splatting the dictionary to the test script block as input. If you want |
| 45 | + the name of the test to appear differently for each test case, you can embed tokens into the Name |
46 | 46 | parameter with the syntax 'Adds numbers <A> and <B>' (assuming you have keys named A and B |
47 | | - in your TestCases hashtables.) |
| 47 | + in your ForEach hashtables.) |
48 | 48 |
|
49 | 49 | .PARAMETER Tag |
50 | 50 | Optional parameter containing an array of strings. When calling Invoke-Pester, |
|
97 | 97 | @{ a = 'two'; b = 'three'; expectedResult = 'twothree' } |
98 | 98 | ) |
99 | 99 |
|
100 | | - It 'Correctly adds <a> and <b> to get <expectedResult>' -TestCases $testCases { |
| 100 | + It 'Correctly adds <a> and <b> to get <expectedResult>' -ForEach $testCases { |
101 | 101 | $sum = Add-Numbers $a $b |
102 | 102 | $sum | Should -Be $expectedResult |
103 | 103 | } |
104 | 104 | } |
105 | 105 | ``` |
106 | 106 |
|
107 | | - Using It with -TestCases to run the same tests with different parameters and expected results. |
| 107 | + Using It with -ForEach to run the same tests with different parameters and expected results. |
108 | 108 | Each hashtable in the `$testCases`-array generates one tests to a total of four. Each key-value pair in the |
109 | 109 | current hashtable are made available as variables inside It. |
110 | 110 |
|
|
128 | 128 | [Parameter(Position = 1)] |
129 | 129 | [ScriptBlock] $Test, |
130 | 130 |
|
131 | | - [Alias("ForEach")] |
132 | | - [object[]] $TestCases, |
| 131 | + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidAssignmentToAutomaticVariable', '', Justification = 'ForEach is not used in Foreach-Object loop')] |
| 132 | + [Alias("TestCases")] |
| 133 | + [object[]] $ForEach, |
133 | 134 |
|
134 | 135 | [String[]] $Tag, |
135 | 136 |
|
|
162 | 163 | } |
163 | 164 | } |
164 | 165 |
|
165 | | - if ($PSBoundParameters.ContainsKey('TestCases')) { |
166 | | - if ($null -ne $TestCases -and 0 -lt @($TestCases).Count) { |
167 | | - New-ParametrizedTest -Name $Name -ScriptBlock $Test -StartLine $MyInvocation.ScriptLineNumber -Data $TestCases -Tag $Tag -Focus:$Focus -Skip:$Skip |
| 166 | + if ($PSBoundParameters.ContainsKey('ForEach')) { |
| 167 | + if ($null -ne $ForEach -and 0 -lt @($ForEach).Count) { |
| 168 | + New-ParametrizedTest -Name $Name -ScriptBlock $Test -StartLine $MyInvocation.ScriptLineNumber -Data $ForEach -Tag $Tag -Focus:$Focus -Skip:$Skip |
168 | 169 | } |
169 | 170 | else { |
170 | 171 | # @() or $null is provided do nothing |
|
0 commit comments