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

后端 未结 6 781
自闭症患者
自闭症患者 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:13

    I think some reason should like the following:

    1. If you move @Before contents to Constructor, That's fine, but the @After contents where you get to move?
    2. The differences of Constructor and @Before/@After is that Constructor should be used to instance some for class, @Before/@After is for preparing test case resources.

提交回复
热议问题