First off, big thanks go to 🐦Ryan Ephgrave, an incredibly talented and easy to work with PowerShell and dotnet god I have the pleasure to learn from over at #BigBank™ (its a great thing LinkedIn doesn’t exist…)
We had a situation arise recently where we needed to create some Integration tests in Pester to validate a long list of web pages to be sure they responded after a deployment. I started out manually writing a litany of Pester tests by hand like this:
Context 'Post Deployment Validation' { It 'Website #1 should be accessible' { $url = 'https://someserver:someport/someEndpoint' $results = Invoke-WebRequest -Uri $url -UseDefaultCredentials $results.StatusCode | should be 200 } It 'Website #2 should be accessible' { $url = 'https://someOtherserver:someport/someEndpoint' $results = Invoke-WebRequest -Uri $url -UseDefaultCredentials $results.StatusCode | should be 200 }[...] }
I spoke with the team about what I was doing and Ryan drew my attention to the very neat TestCases
of Pester, which you can read more about here.
With a bit of work, I converted my long list of tests (which I typed by hand…why? Because I finally got a PS4 and I stayed up too late playing Sekiro!) into a JSON file like this.
[ { "SiteName" : "Our Home Page", "Url" : "https://someserver:someport/someEndpoint" }, { "SiteName" : "Our WebApp #1", "Url" : "https://someOtherserver:someport/someEndpoint" } ]
Then to hook this up to our Pester test from before and… Continue reading