This document provides comprehensive information about the testing infrastructure for the AsBuiltReport.Core PowerShell module.
The AsBuiltReport.Core module includes a complete testing suite powered by Pester 5, covering:
- Module manifest and structure validation
- Unit tests for all public functions
- Integration tests for module loading and dependencies
- Code quality tests for PowerShell best practices
- Automated CI/CD pipeline for continuous testing
Ensure you have PowerShell 7.4 or later installed:
$PSVersionTable.PSVersion# Install Pester 5+
Install-Module -Name Pester -MinimumVersion 5.0.0 -Force
# Install PSScriptAnalyzer for code quality checks
Install-Module -Name PSScriptAnalyzer -Force
# Install PScribo (required by AsBuiltReport.Core)
Install-Module -Name PScribo -MinimumVersion 0.11.1 -ForceThe easiest way to run tests is using the included helper script:
# Run all tests
.\Tests\Invoke-Tests.ps1
# Run only unit tests
.\Tests\Invoke-Tests.ps1 -TestType Unit
# Run with code coverage
.\Tests\Invoke-Tests.ps1 -CodeCoverage -ShowCodeCoverage
# Run with XML output for CI/CD
.\Tests\Invoke-Tests.ps1 -OutputFormat NUnitXmlTests/
├── AsBuiltReport.Core.Tests.ps1 # Module-level tests
├── Unit/ # Unit tests for individual functions
│ ├── New-AsBuiltReport.Tests.ps1
│ ├── New-AsBuiltConfig.Tests.ps1
│ └── New-AsBuiltReportConfig.Tests.ps1
├── Integration/ # Integration tests
│ └── ModuleImport.Tests.ps1
├── Quality/ # Code quality tests
│ └── CodeQuality.Tests.ps1
└── README.md # Detailed test documentation
Tests the overall module structure and configuration:
- ✓ Module manifest validation
- ✓ Correct GUID and version
- ✓ Required dependencies (PScribo)
- ✓ Exported functions
- ✓ Module metadata (tags, URIs, etc.)
- ✓ File structure (Src/Public/Private folders)
- ✓ Language support (en-US and other locales)
Tests individual functions in isolation:
- ✓ Parameter validation and types
- ✓ Parameter aliases (Target/Server/IP, etc.)
- ✓ Multiple parameter sets (Credential, Token, InteractiveAuth)
- ✓ Format validation (Word, HTML, Text)
- ✓ Orientation validation (Portrait, Landscape)
- ✓ Help documentation completeness
- ✓ Argument completers
- ✓ Error handling for invalid inputs
- ✓ Mandatory parameters
- ✓ Parameter aliases
- ✓ Folder path validation
- ✓ Force/Overwrite functionality
- ✓ Help documentation
- ✓ Error handling
- ✓ Parameter structure
- ✓ CmdletBinding verification
- ✓ Help documentation
- ✓ Output type validation
Tests module integration and dependencies:
- ✓ Module imports without errors
- ✓ All public functions load correctly
- ✓ Private functions remain private
- ✓ PScribo dependency loads
- ✓ Version compatibility
- ✓ Language file loading
- ✓ Metadata validation
Tests code quality and best practices:
- ✓ PowerShell syntax validation (PSParser)
- ✓ AST parsing validation
- ✓ File encoding (UTF-8)
- ✓ Comment-based help for all public functions
- ✓ CmdletBinding on all functions
- ✓ Approved PowerShell verbs
- ✓ Manifest completeness
- ✓ No wildcard exports
- ✓ Documentation files (README, CHANGELOG, LICENSE)
- ✓ Language file consistency across cultures
The module includes a dedicated GitHub Actions workflow (.github/workflows/Pester.yml) that:
-
Runs on Multiple Events
- Push to main/dev/master branches
- Pull requests to main/dev/master
- Manual workflow dispatch
-
Platform
- Windows Server (latest)
-
Test Jobs
- Test Job: Runs
Tests\Invoke-Tests.ps1with code coverage - Analyze Job: Runs PSScriptAnalyzer for code quality
- Test Job: Runs
-
Artifacts
- Test results (NUnit XML)
- Code coverage reports (JaCoCo XML)
- ✅ Automatic module dependency installation
- ✅ Code coverage analysis
- ✅ PSScriptAnalyzer static analysis
- ✅ Uses the same test script as local development
Add these to your README.md:

[](https://codecov.io/gh/AsBuiltReport/AsBuiltReport.Core)# Basic test execution
Invoke-Pester -Path ./Tests
# Detailed output
Invoke-Pester -Path ./Tests -Output Detailed
# Specific test file
Invoke-Pester -Path ./Tests/Unit/New-AsBuiltReport.Tests.ps1
# With code coverage
$Config = New-PesterConfiguration
$Config.Run.Path = './Tests'
$Config.CodeCoverage.Enabled = $true
$Config.CodeCoverage.Path = './AsBuiltReport.Core/**/*.ps1'
$Config.Output.Verbosity = 'Detailed'
Invoke-Pester -Configuration $Config# Run all tests with detailed output
.\Tests\Invoke-Tests.ps1
# Run specific test category
.\Tests\Invoke-Tests.ps1 -TestType Unit
.\Tests\Invoke-Tests.ps1 -TestType Integration
.\Tests\Invoke-Tests.ps1 -TestType Quality
# Enable code coverage analysis
.\Tests\Invoke-Tests.ps1 -CodeCoverage -ShowCodeCoverage
# Export results to XML
.\Tests\Invoke-Tests.ps1 -OutputFormat NUnitXml
.\Tests\Invoke-Tests.ps1 -OutputFormat JUnitXml
# Combine options
.\Tests\Invoke-Tests.ps1 -TestType Unit -CodeCoverage -ShowCodeCoverage -OutputFormat NUnitXmlWhen adding new tests, follow these best practices:
-
Use Pester 5 Syntax
BeforeAll { # Setup code } Describe 'Feature Name' { Context 'Specific Scenario' { It 'Should do something specific' { # Test code $Result | Should -Be $Expected } } } AfterAll { # Cleanup code } -
Organize Tests Logically
- Place unit tests in
Tests/Unit/ - Place integration tests in
Tests/Integration/ - Place quality tests in
Tests/Quality/
- Place unit tests in
-
Use Descriptive Names
# Good It 'Should throw error when OutputFolderPath does not exist' # Bad It 'Test 1'
-
Test Both Positive and Negative Cases
It 'Should accept valid format parameter' { # Positive test } It 'Should reject invalid format parameter' { # Negative test }
-
Clean Up After Tests
AfterAll { Remove-Module -Name 'AsBuiltReport.Core' -Force -ErrorAction SilentlyContinue if (Test-Path $TestFolder) { Remove-Item -Path $TestFolder -Recurse -Force } } -
Mock External Dependencies
BeforeAll { Mock -CommandName 'Get-ExternalData' -MockWith { return @{ Status = 'Success' } } }
- Overall Coverage: Target 80%+ code coverage
- Public Functions: 100% parameter validation coverage
- Critical Paths: 100% coverage for core functionality
- Error Handling: All error paths should be tested
Solution: Ensure the module path is correct in your test files:
$ModulePath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\AsBuiltReport.Core\AsBuiltReport.Core.psd1'
Import-Module $ModulePath -ForceSolution: Verify the coverage path includes your module files:
$Config.CodeCoverage.Path = './AsBuiltReport.Core/**/*.ps1'Solution: Run PSScriptAnalyzer locally to identify issues:
Invoke-ScriptAnalyzer -Path ./AsBuiltReport.Core -RecursePossible Causes:
- PowerShell version differences
- Module dependencies not installed
- Platform-specific code (Windows vs Linux)
- File path case sensitivity (Linux/macOS)
Solution:
- Check the CI logs for specific errors
- Test on multiple platforms locally using Docker
- Ensure all dependencies are in the workflow YAML
# Run specific test with detailed output
Invoke-Pester -Path ./Tests/Unit/New-AsBuiltReport.Tests.ps1 -Output Detailed
# Run with debug output
$DebugPreference = 'Continue'
Invoke-Pester -Path ./Tests/Unit/New-AsBuiltReport.Tests.ps1
# Run single test
Invoke-Pester -Path ./Tests/Unit/New-AsBuiltReport.Tests.ps1 -FullNameFilter '*Should have Report parameter*'- Unit Tests: ~10-30 seconds
- Integration Tests: ~5-10 seconds
- Quality Tests: ~30-60 seconds
- Total Suite: ~1-2 minutes
- Use
BeforeAllfor expensive setup operations - Mock external calls to avoid network delays
- Clean up resources in
AfterAllinstead ofAfterEach - Use
-Skipfor tests that don't apply to current environment
- ✅ Write tests before fixing bugs (TDD)
- ✅ Test edge cases and boundary conditions
- ✅ Use meaningful test descriptions
- ✅ Keep tests independent and isolated
- ✅ Clean up resources after tests
- ✅ Update tests when changing functionality
- ✅ Aim for high code coverage
- ❌ Don't test PowerShell itself
- ❌ Don't make tests dependent on each other
- ❌ Don't use hardcoded file paths
- ❌ Don't skip cleanup steps
- ❌ Don't ignore failing tests
- ❌ Don't commit test artifacts (XML files, coverage reports)
For issues, questions, or contributions:
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: AsBuiltReport.com
This testing infrastructure is part of the AsBuiltReport.Core project and follows the same license.