Table of Contents – Improving Code Coverage
This, was a very involved chapter, and it required a good deal of concentration. We first had to understand a good amount of PowerShell that we then had to write tests around. Even so, this turned out to be a great opportunity in that we had not typically seen some of the examples that were included in this chapter. We saw multiple mocks for the same command, mocks that included New-MockObject, a good deal of ParameterFilter parameters on our mocks, and even a Foreach around an Assert-MockCalled command. Awesome.
All that said, the idea behind this chapter wasn’t to present various ideas for testing — although it most certainly did — it was to do a full code walkthrough in regard to code coverage. Once we understood the example function, we met three initial tests someone new at Pester might write. Then the example took off, with a whole new test suite written by Adam. After a multiple page understanding of what had been written, we tested the code coverage. It wasn’t perfect, but it was close. A few changes and we got to a place where the percentage was high enough to feel confident that everything in this function had been tested.
There was a quote I liked, I’ll share in closing. I liked it because we got an image that just like you or me, Adam walked the code in his own mind and extracted those things in which he wanted to test. “These tests were created by following the various code paths of the function. I followed the code from top to bottom and when it “did something,” I created a test for that thing. I followed all code paths.”
Well, next we’ll start Part V, and work to wrap up this chapter-by-chapter book review. I’m excited to finish, but mostly so I can head back and review a touch before I find my next Pester resource. I don’t feel like I know it, know it, so like PowerShell before this, I’ll keep looking for new information to consume in regard to Pester. Back soon.