Different Singleton instances with JUnit tests

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

    Spring provides the DirtiesContext annotation for this particular use case where you need new instances of the singleton beans for each testcase. It basically creates a new application context for each testcase/testclass which has this annotation applied.

    0 讨论(0)
提交回复
热议问题