October 2017
Intermediate to advanced
440 pages
11h 47m
English
When the inputs and outputs of a function are being repetitively tested, the TestCases parameter of It can be used. Test cases are defined in a hashtable, which is splatted into It as a set of parameters.
The four test cases used in the preceding example might be rewritten as follows:
$testCases = @(
@{ Value = 1; ExpectedResult = 1 }
@{ Value = 4; ExpectedResult = 2 }
@{ Value = 9; ExpectedResult = 33 }
@{ Value = 16; ExpectedResult = 44 }
)
It 'Calculates the square root of <Value>to be<ExpectedResult>' -TestCases $testCases {
param (
$Value,
$ExpectedResult
)
Get-SquareRoot $Value | Should -Be $ExpectedResult
}
The preceding tests still contain errors; the advantage of this approach is that Pester will report success or failure ...
Read now
Unlock full access