【发布时间】:2020-02-07 12:11:12
【问题描述】:
有没有办法使用 scalamock 调用存根对象上的真实方法?
我希望能够做这样的事情:
class MySpec extends FunSpec with Matchers with MockFactory {
trait MyTrait {
def f1: Int
def f2: Int = f1
}
describe("my feature") {
it("should work") {
val t = stub[MyTrait]
(t.f1 _).when().returns(15)
// I would like to do the following:
// (t.f2 _).when().callRealMethod()
t.f2 should be (15)
}
}
}
注意:我可以通过将 f2 设为 final 来解决此问题,但我想知道是否有办法在不更改被测代码的情况下解决此问题。
【问题讨论】: