Я не вижу ничего плохого в том, что вы пытались сделать, хотя что-то может быть не так в полном контексте вашей попытки.
Мне удалось смоделировать запуск процесса следующим образом:
Describe 'tests involving start-process' {
Context 'no mock' {
It 'needs to be mocked' {
# demonstrate that it's not mocked
# ... you'll have to dismiss the console window by hand
start-process cmd "/c pause" | should -Be $null
}
}
Context 'mocked' {
Mock start-process {"fake execution"}
It 'can be mocked' {
start-process cmd "/c pause" | should -Be "fake execution"
}
}
}
Это дает следующий вывод:
> Invoke-Pester ".\test.tests.ps1"
____ __
/ __ \___ _____/ /____ _____
/ /_/ / _ \/ ___/ __/ _ \/ ___/
/ ____/ __(__ ) /_/ __/ /
/_/ \___/____/\__/\___/_/
Pester v4.9.0
Executing all tests in '.\test.tests.ps1'
Executing script .\test.tests.ps1
Describing tests involving start-process
Context no mock
[+] needs to be mocked 27ms
Context mocked
[+] can be mocked 14ms
Tests completed in 348ms
Tests Passed: 2, Failed: 0, Skipped: 0, Pending: 0, Inconclusive: 0
Возможно, вам нужно установить последнюю версию Pester? Я обновил до 4.9 с install-module pester -force -skippublishercheck