Different Singleton instances with JUnit tests

后端 未结 7 1068
遥遥无期
遥遥无期 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:03

    I assume you have a private static field within your singleton class to store the initialized instance.

    If you do not want to modify your code, you can define a teardown method which run after every test, and in this method you set this static field to null via reflection as seen here.

提交回复
热议问题