February 2019
Intermediate to advanced
626 pages
15h 51m
English
When the input and output 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:
Describe Get-SquareRoot { It 'When the value is <Value>, the square root is <ExpectedResult>' -TestCases @(
@{ Value = 1; ExpectedResult = 1 }
@{ Value = 4; ExpectedResult = 2 }
@{ Value = 9; ExpectedResult = 33 }
@{ Value = 16; ExpectedResult = 44 }
) { 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 a success ...
Read now
Unlock full access