This directory contains Pester tests for the CAPI2Tools PowerShell module.
- CAPI2Tools.Tests.ps1 - Main test suite covering all module functions
Install Pester module (if not already installed):
Install-Module -Name Pester -Force -SkipPublisherCheck# Run all tests with detailed output
Invoke-Pester -Path .\Tests\CAPI2Tools.Tests.ps1 -Output Detailed
# Run all tests (default output)
Invoke-Pester -Path .\Tests\CAPI2Tools.Tests.ps1# Run only unit tests (excludes integration tests)
Invoke-Pester -Path .\Tests\CAPI2Tools.Tests.ps1 -ExcludeTag Integration
# Run only integration tests
Invoke-Pester -Path .\Tests\CAPI2Tools.Tests.ps1 -Tag Integration# Run tests with code coverage analysis
$Config = New-PesterConfiguration
$Config.Run.Path = '.\Tests\CAPI2Tools.Tests.ps1'
$Config.CodeCoverage.Enabled = $true
$Config.CodeCoverage.Path = '.\CAPI2Tools.psm1'
$Config.CodeCoverage.OutputPath = '.\Tests\coverage.xml'
Invoke-Pester -Configuration $ConfigThe test suite is organized into the following contexts:
-
Module Import and Structure
- Module loading validation
- Version checking
- Exported functions and aliases
-
Error Code Mappings
- Known error code translation
- Unknown error code handling
- Error code normalization
-
Display Character Helper Functions
- Unicode character retrieval
- Cross-version compatibility
-
Convert-EventLogRecord Function
- Event record processing
- Pipeline support
-
Export-CapiEvents Function
- CSV export
- JSON export
- HTML export (with certificate header)
- XML export
- Format auto-detection
-
Get-CapiErrorAnalysis Function
- Error detection
- Summary generation
-
Compare-CapiEvents Function
- Event comparison logic
- Custom labels
-
Format-XML Function
- XML formatting
- Custom indentation
-
Find-CapiEventsByName Function
- Parameter validation
- Pipeline support
-
Get-CapiTaskIDEvents Function
- TaskID-based event retrieval
-
Event Log Management Functions
- Enable/Disable/Clear operations
- WhatIf support
- Backup functionality
-
Workflow Functions
- Troubleshooting workflow
- Session management
-
Parameter Validation
- ValidateSet attributes
- Mandatory parameters
-
Error Handling
- Graceful error handling
- Invalid input handling
- Complete workflow scenarios
- End-to-end export operations
- Error analysis workflows
Expected test results:
- Total Tests: ~80+ test cases
- Coverage: Core functionality and error paths
- Duration: < 30 seconds (unit tests only)
These tests can be integrated into CI/CD pipelines:
# Example GitHub Actions workflow
- name: Run Pester Tests
run: |
Install-Module -Name Pester -Force -SkipPublisherCheck
Invoke-Pester -Path .\Tests\CAPI2Tools.Tests.ps1 -Output Detailed -CIWhen adding new functionality to CAPI2Tools:
- Add corresponding test cases in
CAPI2Tools.Tests.ps1 - Follow the existing test structure (Describe/Context/It)
- Use descriptive test names
- Include both positive and negative test cases
- Run all tests before committing changes
- Isolation: Each test should be independent
- Mock Data: Use mock data for event testing (no live event log dependency)
- Cleanup: Use BeforeAll/AfterAll for setup/teardown
- Readability: Test names should clearly describe what's being tested
- Fast: Unit tests should execute quickly
- Ensure module is in the correct path
- Check Pester version (v5+ recommended)
- Verify no other instances of module are loaded
- Check file permissions for test exports
# Force reload the module
Remove-Module CAPI2Tools -Force -ErrorAction SilentlyContinue
Import-Module .\CAPI2Tools.psm1 -ForceWhen contributing tests:
- Maintain consistent formatting
- Add comments for complex test logic
- Ensure tests pass before submitting PR
- Update this README if adding new test categories