Can I mock a super class method call?

后端 未结 6 1362
旧巷少年郎
旧巷少年郎 2021-02-12 22:11

Sometimes, you want to test a class method and you want to do an expectation on a call of a super class method. I did not found a way to do this expectation in java using easymo

6条回答
  •  醉话见心
    2021-02-12 22:39

    No, there is no way of mocking super class methods with jMock.

    However there is a quick-and-dirty solution to your problem. Suppose you have class A and class B extends A. You want to mock method A.a() on B. You can introduce class C extends B in your test code and override the method C.a() (just call super, or return null, id does not matter). After that mock C and use the mock everywhere, where you'd use B.

提交回复
热议问题