How to Mock a Static Singleton?

后端 未结 7 703
伪装坚强ぢ
伪装坚强ぢ 2020-12-15 23:05

I have number of classes I\'ve been asked to add some unit tests to with Rhino Mocks and having some issues.

First off, I know RhinoMocks doesn\'t allow for the mock

7条回答
  •  既然无缘
    2020-12-15 23:24

    Check out Dependency Injection.

    You've already began this, but for hard to test classes (statics etc...) you can use the adapter design pattern to write a wrapper around this hard to test code. Using the interface of this adapter, you can then test your code in isolation.

    For any unit testing advice, and further testing issues check out the Google Testing Blog, specifically Misko's articles.

    Instance

    You say you are writing tests, so it may be too late, but could you refactor the static to the instance? Or is there a genuine reason why said class should remain a static?

提交回复
热议问题