jmock mocking a static method

前端 未结 3 1055
-上瘾入骨i
-上瘾入骨i 2020-12-04 01:27

I have a static method in my code that I would like somehow to mock.

I am using jmock.

One way I suppose I could do this is to have \"wrapper class\" around

3条回答
  •  春和景丽
    2020-12-04 02:05

    We don't support mocking static methods in jMock because it doesn't fit our design approach. We prefer not to use static methods for significant features that can affect the state of the system. We tend to use them just to support the OO code and make it more readable. That's why we view mocking a static methods as a hint that there's a problem. One exception is where it's in a third-party library, but we would probably wrap that in something more object-oriented anyway.

提交回复
热议问题