Table of Contents – It Blocks
Today, we’ll review some of what was offered by the It Blocks chapter. Things, are getting interesting.
It turns out that It blocks are our main unit for testing. These blocks are the smallest blocks and belong inside a Describe and/or any Context blocks, if you’re using those. As they’re the smallest, it’s always best to keep them “simple, and as straightforward as possible.” The idea was that we should test everything independently of each other when we can, and that when we can’t, there needs to be a good idea as to why. That lead me to this write this Tweet today, where I questioned whether I should test all the permitted random password length values (4 – 35), that my random password function would accept in a single test, or one test — one It block — per value from 4 – 35. Take a look and let me know what you think as I’ve done both below. I haven’t actually seen any replies yet besides a few likes, and I still don’t know which I’ll end up using.
Which would you do? Test all the permitted random password lengths in one #Pester test, or test the permitted length in individual tests? #PowerShell pic.twitter.com/tawx4erUEA
— Tommy Maynard (@thetommymaynard) March 26, 2018
We also learned to have your It block throw a terminating error if an expectation isn’t met, the five possible results of an It block (passed, failed, etc.), using the Pending and Skip parameters on our It blocks, and finally about the Set-TestInconclusive option for It blocks that ensure a test is never run, under any circumstance.
Next we’re talking about Should. That should be interesting.
hi,
Maybe you can take a look at “-TestCases”, you could parameterize the inputs (4..35) and outputs (4..35)
Thanks for the post, Xiang. I’ve actually been thinking the same thing!