Adding Pester tests to a PowerShell module is probably one of the most valuable development activities you’ll be able to perform, and I’d encourage you to do it early in your project. I left it until rather late with SQLChecks, and as a result have broken the module several times.
While some of breaks were definitely edge cases (and I don’t think I have the the foresight to write a test that would have caught them), one of the most egregious errors caused SQLChecks to not export any functions at all. In this post I’ll walk through the steps needed to do just that, which in brief are:
- Create a Pester test for the module
- Run the test locally, demonstrating that it will fail when the module doesn’t export any functions
- Schedule the test to run automatically every time a commit is pushed to the GitHub repo (using AppVeyor)
- Display the build status and number of passing tests on the Github readme
And once we’re done a quick glance at our readme will show: