在PowerShell中编写脚本时,我需要调用外部可执行文件(.exe)。目前我正在采用TDD方法开发此脚本,因此我需要模拟对此.exe文件的调用。
我尝试了以下代码:
我收到了这个回复:
有没有一种方法可以模拟这种调用,而不需要将它们封装在函数内部?
我尝试了以下代码:
Describe "Create-NewObject" {
Context "Create-Object" {
It "Runs" {
Mock '& "c:\temp\my.exe"' {return {$true}}
Create-Object| Should Be $true
}
}
}
我收到了这个回复:
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
有没有一种方法可以模拟这种调用,而不需要将它们封装在函数内部?