Junit before class ( non static )

后端 未结 8 650
旧巷少年郎
旧巷少年郎 2020-12-02 12:12

Are there any best practices to get Junit execute a function once in a test file , and it should also not be static.

like @BeforeClass on non static fun

8条回答
  •  渐次进展
    2020-12-02 12:30

    The article discuss 2 very nice solutions for this problem:

    1. "clean" junit with custom Runner (using interface but you could extend it with a custom annotation e.g. @BeforeInstance)
    2. Spring execution listeners as mentioned by Espen before.

提交回复
热议问题