Mocking class functions with Pester 5 and PowerShell 7
问题 Does anyone have an example of mocking a dot-sourced class function with Pester 5 and PowerShell 7? Thank you. Edit: example Classes\MyClass.ps1: class MyClass { [void] Run() { Write-Host "Class: Invoking run..." } } MyModule.psm1: # Import classes . '.\Classes\MyClass.ps1' # Instantiate classes $MyClass = [MyClass]::new() # Call class function $MyClass.Run() 回答1: Pester only mocks commands - not classes or their methods. The easiest way to "mock" a PowerShell class for method dispatch