我在尝试模拟一个PowerShell 5类方法时遇到了问题,执行测试时,我收到了错误消息“CommandNotFoundException:找不到命令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"
}
}