Open nohwnd opened 7 years ago
Some more concepts, probably the syntax with -Property
parameter would be the best. Lot of this stuff can be done more easily when Assert-Equivalent
is done. Then we can just give it simple object with five properties, allow ignoring missing properties on the actual object and we're done.
@nohwnd I think I've got a pattern that might work for simultaneous reporting of failed assertions in this usage, but without needing CombineAssert
:
I'd rather not duplicate your work so I'm wondering if you've already got a solution for that.
Here's a gist of the chaining pattern I was thinking of. If each Assert-
function follows the pattern, I think you can get the desired output without coupling to Pester.
Describe 'chained asserts' {
It 'fails some of these' {
24 |
Assert-Something {-not ($_ % 3)} 'divisible by 3' |
Assert-Something {-not ($_ % 4)} 'divisible by 4' |
Assert-Something {-not ($_ % 5)} 'divisible by 5' |
Assert-Something { $_ -gt 30 } 'greater than 30' |
Assert-Something { $_ -ge 0 } 'not negative'
}
}
outputs
That's pretty clever, propagating the value throught the pipeline and failing the last assertion first. Problem is that the assertions are collecting input in the process block, and then asserting on it in the end block. Is there any way we could use this?
You're right about this technique not working for exceptions in the end
block. I've got a more elaborate pattern that looks promising for Assert-Any
and any other assertion that needs to operate on the entire contents of collections. But it depends on more explicitly stating intentions around testing collections versus collection contents. That's the discussion in #29.
The first assertion to fail will fail the whole test. This leaves you with partial infomation, about why your test failed. Have a test containing these assertions:
Your test initally fails with "StatusCode is '400' but expected '200'.". You fix the call in
Get-WebRequest
and try again. Your test now fails with "Content is "abc" but expected 'Hello'".Multiply this by tens of tests that change failure messages as you progress fixing your code, and you have to work very hard to understand what you need to do to fix your code.
Compare that with this failure message:
This message contains all the failure messages combined, and tells you all the things that are wrong with your code. This allows for simpler overview of failures and easier development.
It is also extremely useful on build servers where you want to collect as much information about the failure as you can, to avoid fixing the code over multiple builds which can take many minutes to finish.