Can I mock a super class method call?

后端 未结 6 1346
旧巷少年郎
旧巷少年郎 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:44

    I don't think I'd mock out a super call - it feels to me like the behaviour there is part of the behaviour of the class itself, rather than the behaviour of a dependency. Mocking always feels like it should be to do with dependencies more than anything else.

    Do you have a good example of the kind of call you want to mock out? If you want to mock out a call like this, would it be worth considering composition instead of inheritance?

提交回复
热议问题