setUp/tearDown (@Before/@After) why we need them in JUnit?

后端 未结 6 764
自闭症患者
自闭症患者 2020-12-02 10:18

I believe that we are all know that setUp (@Before) will execute before any test method and tearDown(@After) will execute after test method.

Also we know that Junit

6条回答
  •  温柔的废话
    2020-12-02 11:08

    A custom runner such as SpringJUnit4ClassRunner may need to run some codes between the constructor and @Before method. In this case, the runner may inject some dependency which the @Before methods needs. But dependency injection can only be run after the object is constructed.

提交回复
热议问题