liveBook · Manning

Integration test

As explained in Practical Automation with PowerShell: Effective scripting from the console to the cloud

Integration testing verifies that multiple software components or systems function correctly together.

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

How Practical Automation with PowerShell: Effective scripting from the console to the cloud covers it

How deep it goes
Explains mocking boundaries and builds multi-function Pester scenarios, then extends assertions to live external data.
Examples
Demonstrates KB4521858, KB4565912, Get-VulnerabilityStatus, Get-HotFix, and Microsoft Update Catalog results.
What it assumes
Assumes PowerShell functions and Pester mocks while introducing integration testing after unit-test construction.
What you can do after
Apply it via Pester to validate collaborating PowerShell functions while controlling external cmdlet responses.
How it connects
Connects unit tests, Pester mocks, external data, web scraping, and continuous testing in GitHub pull requests.

Also explained in

Compare how 31 books explain integration test →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Practical Automation with PowerShell: Effective scripting from the console to the cloud. The section links point to the parts of the book it draws on.