JUnit: using constructor instead of @Before

前端 未结 8 809
旧巷少年郎
旧巷少年郎 2020-12-04 14:10

I\'m using JUnit 4. I can\'t see the difference between initializing in the constructor or using a dedicated init function annotated by @Before. Does this mean

8条回答
  •  温柔的废话
    2020-12-04 14:39

    @Before does make sense to use for several reasons. It makes your test code more readable. It matches @After annotation which is responsible for releasing used resources and is a counterpart of the @BeforeClass annotation.

提交回复
热议问题