以下脚本在带点运行时有效,但在用invoke-pester(运行Pester版本4.6.0)调用时无法运行。我是在做错什么还是invoke-pester有问题?
using module "./Test.psm1"
Describe "Unit Test" -Tag 'Unit' {
Context 'test' {
It 'return' {
mock Write-Verbose { write-host $Message }
$T = [Test]::new()
$T.createoutput()
assert-MockCalled Write-Verbose
}
}
}
Test.psm1:
class Test{
[void]createoutput(){
Write-Verbose 'hello'
}
}
答案 0 :(得分:1)
问题出在您的模拟设置上。模拟模块时,there is some additional work required。
实际情况:
using module ./Test.psm1
Describe 'Unit Test' -Tag 'Unit' {
Context 'test' {
It 'mocks correctly' {
Mock Write-Verbose {} -ModuleName Test
$T = [Test]::new()
$T.createoutput()
Assert-MockCalled Write-Verbose -ModuleName Test
}
}
}