Different Singleton instances with JUnit tests

后端 未结 7 1013
遥遥无期
遥遥无期 2021-01-31 17:41

I have a standalone singleton which successfully passes the test. But with a group of tests this fails since once a singleton is defined it does not allow to reset the instance.

7条回答
  •  轮回少年
    2021-01-31 18:04

    Singleton instance needs to be passed to SUT by test itself - that way you create singleton (and destroy) for each test. Adopting IoC and mocking framework, like Mockito, would render this approach almost trivial.

提交回复
热议问题