Junit before class ( non static )

后端 未结 8 648
旧巷少年郎
旧巷少年郎 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:13

    Easily use @BeforeAllMethods/@AfterAllMethods annotations to run a method inside the instance context (non-static), where all injected values will be available.

    There is a special testing library for this:

    https://mvnrepository.com/artifact/org.bitbucket.radistao.test/before-after-spring-test-runner/0.1.0

    https://bitbucket.org/radistao/before-after-spring-test-runner/

    The only limitation: works only for Spring testing.

    (I'm the developer of this testing library)

提交回复
热议问题