【发布时间】:2017-03-24 20:23:59
【问题描述】:
您好,我想使用特定参数对方法进行存根,并使用辅助方法获取结果
val myDAOMock = stub[MyDao]
(myDAOMock.getFoos(_:String)).when("a").returns(resHelper("a"))
//btw-is there a way to treat "a" as a parameter to the stubbed method and to the return ?
(myDAOMock.getFoos(_:String)).when("b").returns(resHelper("b"))
def resHelpr(x:String) = x match{
case "a" => Foo("a")
case "b" => Foo("b")
}
但似乎在我的测试中我只能捕获一个,因为第二次测试失败(不管我运行测试的顺序如何)
"A stub test" must{
"return Foo(a)" in{
myDAOMock.getFoos("a")
}
"return Foo(b)" in{
myDAOMock.getFoos("b") //this one will fail on null pointer exception
}
如何改进我的存根?
【问题讨论】: