我在尝试模拟powershell 5类方法时遇到问题,在执行测试时,我收到错误"CommandNotFoundException:找不到Command FunctionToMock".我试图通过模拟"FunctionToMock"来单元测试"OutputToOverwrite"方法.我想我必须首先嘲笑ChocoClass本身,但我不知道该怎么做.谢谢.
Class ChocoClass
{
[string] OutputToOverwrite()
{
return $this.FunctionToMock()
}
[string] FunctionToMock()
{
return "This text will be replaced"
}
}
Describe "Testing mocking"{
it "Mock test"{
Mock FunctionToMock -MockWith {return "mystring"}
$package = New-Object ChocoClass
$expected = $package.OutputToOverwrite()
$expected | should BeExactly "mystring"
}
}
Run Code Online (Sandbox Code Playgroud)