3
PowerShell에서 스크립트를 개발하기 위해 외부 실행 파일 (.exe)을 호출해야합니다. 현재 TDD 방식으로이 스크립트를 개발 중이므로이 .exe 파일에 대한 호출을 조롱해야합니다. Pester를 사용하여 exe 파일에 대한 호출을 조롱하는 방법은 무엇입니까?
나는 이것을 시도 :Describing Create-NewObject
Context Create-Object
[-] Runs 574ms
CommandNotFoundException: Could not find Command & "C:\temp\my.exe"
at Validate-Command, C:\Program Files\WindowsPowerShell\Modules\Pester\Functions\Mock.ps1: line 801
at Mock, C:\Program Files\WindowsPowerShell\Modules\Pester\Functions\Mock.ps1: line 168
at <ScriptBlock>, C:\T\Create-NewObject.tests.ps1: line 13
Tests completed in 574ms
Passed: 0 Failed: 1 Skipped: 0 Pending: 0 Inconclusive: 0
없는 함수 내부를 캡슐화 통화의 종류를 조롱 할 수있는 방법이 있나요 :
Describe "Create-NewObject" {
Context "Create-Object" {
It "Runs" {
Mock '& "c:\temp\my.exe"' {return {$true}}
Create-Object| Should Be $true
}
}
}
내가이 응답을 얻었다?
function Create-Object
{
$exp = '& "C:\temp\my.exe"'
Invoke-Expression -Command $exp
}
그리고해야 모습 모의 테스트 :
Describe "Create-NewObject" {
Context "Create-Object" {
It "Runs" {
Mock Invoke-Expression {return {$true}} -ParameterFilter {($Command -eq '& "C:\temp\my.exe"')
Create-Object| Should Be $true
}
}
}
"동의"하는 것을 잊지 마십시오 당신의 자신의 –