5/9/2023 0 Comments Pester code coverageSoon, it became clear to me that that I would have to make significant changes which meant that I had to work on my PowerShellTemplate repository, where advanced Pester test cases are also covered.Īll the changes are available in this pull request and in the following sections I’ll focus on the major adaptations required. It turns out that there has been a new version (v5) of Pester which broke compatibility compared with the previous version (v4). I’ve not been hands on for a while and it took me some time to figure out that the tests were failing and why. It "switches debug attribute to false for a web.Recently somebody submitted a pull request in my SemVerPS which failed with the Appveyor’s CI pipeline. Setup -File "inetpub\wwwroot\testsite\web.config" ` $sut = (Split-Path -Leaf $MyInvocation.M圜ommand.Path).Replace(".Tests.", ".") $pwd = Split-Path -Parent $MyInvocation.M圜ommand.Path ![]() ![]() I’ll try to go line by line and explain what’s going on:Į1 contents: So Michael has written a test that didn’t require a lot of code, but is actually doing a few cool things. Let’s update our specification (aka Test) and do something useful. So what should we do with this broken function? As it stands now it’s totally empty. Wow, it failed! Why is that? By default Pester will generate a fixture that is silly and won’t ever pass. Here’s his test file after he’s setup his expectations. Now it’s time for Michael to update the test to make it more meaningful. Wanting to see some red he runs the tests by running Invoke-Pester which loads all files that match *.Tests.ps1 recursively in the current directory.Įxecuting all tests in C:\dev\IDeploy\DeployĪs you can see Pester by default makes a failing test. SMUC-PC Create-Fixture Deploy\Functions Ensure-AspNetDebugIsFalseĬreating => Deploy\Functions\Ensure-AspNetDebugIsFalse.ps1Ĭreating => Deploy\Functions\1 The console should look like the following: Then running Import-Module Pester anytime you open up a PowerShell session where you want to use Pester. Setting up Pester is simply a matter of following the instructions at PsGet (author Mike Chaliy has tons of great PowerShell modules)then running Install-Pester. Mike (as he now likes be known as) decides to call his project of tools IDeploy and creates a folder of that name where he does is development. He doesn’t want to repeat the debacle of his previous attempt at being clever.įirst step is to setup a project. Michael Bolton has decided he’s going to automate this step but wants to right it test first. This has made production support people irritable because they now manually tweak the web.config every single time they do a deploy. Net web applications have been deployed on production servers with the debug compilation flag set to true. What I’m going to go through here is the beginning of what could possibly be a real world scenario for a person assigned to write deployment code. Still, probably not the best way to show how it all works. ![]() In fact it’s being tested by the version of Pester that’s under test (although Martin pointed out some uncovered areas). Inside Pester there’s already a trivial Calculator example but it’s not really the best way to demonstrate the app. I wanted to find a way ensure these problems didn’t happen again as well as provide some code coverage to give new entrants to the codebase some confidence that they won’t break everything. We wrote nearly all the code without tests and it came to bite us in the end. The creation of Pester came out of the desire to test some build/deployment infrastructure we were creating for a project. Hi there and welcome to my demo of Pester, a BDD style testing framework for Powershell.
0 Comments
Leave a Reply. |