Why must jUnit's fixtureSetup be static?

前端 未结 8 1509
悲&欢浪女
悲&欢浪女 2020-12-04 07:50

I marked a method with jUnit\'s @BeforeClass annotation, and got this exception saying it must be static. What\'s the rationale? This forces all my init to be on static fiel

8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-04 08:57

    The short answer is this: there is no good reason for it to be static.

    In fact, making it static causes all sorts of problems if you use Junit to execute DBUnit based DAO integration tests. The static requirement interferes with dependency injection, application context access, resource handling, logging, and anything that depends on "getClass".

提交回复
热议问题