An integration test verifies that collaborating code paths work together, rather than checking one isolated function. In PowerShell, Pester can exercise a reusable automation end to end while preserving the real calls between custom functions. section 13.0 section 13.4
Keep the boundary deliberate. Unit tests are self-contained and use mocks to test logic precisely; integration tests do not mock custom functions under test. They may still mock an external cmdlet or service boundary so the full automation can run through controlled conditions. section 13.3.4 section 13.4
Design integration tests around observable operational outcomes:
- Load each collaborating function, then call the top-level function with realistic inputs. section 13.4
- Test a patch found directly, a patch still required, and a missing patch made unnecessary by an installed superseding update. section 13.4
- For live external data, assert stable shapes and ranges—such as a GUID-shaped ID, populated products, known architectures, or a minimum supersedence count—instead of brittle exact values. section 13.4.1
Checking vulnerability status across functions
Get-VulnerabilityStatus first checks a requested patch, then calls Find-KbSupersedence and checks successor patches when needed. An integration test leaves those custom functions real, mocks Get-HotFix responses, and verifies that KB4521858 resolves to installed successor KB4565912 when the original patch is absent. section 13.4
Listing 13.10 Get-VulnerabilityStatus.Integration.Test.ps1
BeforeAll {
Set-Location -Path $PSScriptRoot #1
. ".\Get-HotFixStatus.ps1"
. ".\Find-KbSupersedence.ps1"
. ".\Get-VulnerabilityStatus.ps1"
}
Describe 'Find-KbSupersedence not superseded' {
BeforeAll {
$Id = 'KB4521858'
$Vulnerability = @{
Id = $Id
Product = 'Windows Server 2016'
Computer = 'localhost'
}
Mock ConvertFrom-Html -ParameterFilter{ #2
$URI } -MockWith {
$File = "$($URI.AbsoluteUri.Split('=')[-1]).html"
$Path = Join-Path $PSScriptRoot $File
ConvertFrom-Html -Path $Path
}
}
Context "Patch Found" {
BeforeAll { #3
Mock Get-HotFix {}
}
It "Patch is found on the computer" {
$KBFound = Get-VulnerabilityStatus @Vulnerability
$KBFound | Should -Be $Id
}
}
Context "Patch Not Found" {
BeforeAll { #4
Mock Get-HotFix {
throw ('GetHotFixNoEntriesFound,' +
'Microsoft.PowerShell.Commands.GetHotFixCommand')
}
}
It "Patch is not found on the computer" {
$KBFound = Get-VulnerabilityStatus @Vulnerability
$KBFound | Should -BeNullOrEmpty
}
}
Context "Superseding Patch Found" {
BeforeAll { #5
Mock Get-HotFix {
throw ('GetHotFixNoEntriesFound,' +
'Microsoft.PowerShell.Commands.GetHotFixCommand')
} -ParameterFilter { $Id -ne 'KB4565912' }
Mock Get-HotFix { } -ParameterFilter { #6
$Id -eq 'KB4565912' }
}
It "Superseding Patch is found on the computer" {
$KBFound = Get-VulnerabilityStatus @Vulnerability
$KBFound | Should -Be 'KB4565912'
$cmd = 'Get-HotFix' #7
Should -Invoke -CommandName $cmd -ParameterFilter {
$Id -ne 'KB4565912' } -Times 4
Should -Invoke -CommandName $cmd -ParameterFilter {
$Id -eq 'KB4565912' } -Times 1
}
}
}
This Pester listing shows the integration-test setup: dot-source the collaborating functions, provide test inputs, and mock the external Get-HotFix cmdlet rather than the custom workflow. section 13.4
Use integration tests as a maintenance guardrail alongside unit tests. Keeping both in a GitHub repository supports automatic checks when pull requests are submitted, helping detect breaking changes before updates spread to dependent automations. section 14.4






























