我在尝试模拟 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"
}
}