如何对 Spock 中具有超类的类进行单元测试,该超类调用来自其超类的方法调用?或者如何模拟 Spock 中的超类?
Ex:
class Bar {
def method1(parm1){
//Method actions
}
}
class Foo extends Bar {
def method2(param1, param2) {
//Method actions
super.method1(param1)
}
}
我如何模拟课堂行为Bar
?
您可能会使用您的课程Foo
as a Spy http://docs.spockframework.org/en/latest/interaction_based_testing.html#spies。间谍将创建你的类的一个实例Foo
但使您可以模拟间谍类层次结构中声明的任何公共方法。
def fooInstance = Spy(Foo)
fooInstance.method1(_) >> 'return value'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)