Cleanup after all junit tests

前端 未结 5 1082
小鲜肉
小鲜肉 2020-12-02 22:38

In my project I have to do some repository setup before all tests. This is done using some tricky static rules. However I\'ve got no clue how to do clean up after all the te

5条回答
  •  一整个雨季
    2020-12-02 23:00

    Just encountered the same problem.
    My solution:

    • For a global set up: use (lazy) singleton to access something global that requires instantiation before the tests. The first test that accesses this singleton will trigger the global set up process.
    • For a global tear down: use a Java shutdown hook:
      Runtime.getRuntime().addShutdownHook(new Thread(() -> do_your_global_cleanup())));

提交回复
热议问题