Difference between setUp() and setUpBeforeClass()

后端 未结 4 2290
渐次进展
渐次进展 2020-12-12 09:55

When unit testing with JUnit, there are two similar methods, setUp() and setUpBeforeClass(). What is the difference between these methods? Also, wh

4条回答
  •  天涯浪人
    2020-12-12 10:50

    From the Javadoc:

    Sometimes several tests need to share computationally expensive setup (like logging into a database). While this can compromise the independence of tests, sometimes it is a necessary optimization. Annotating a public static void no-arg method with @BeforeClass causes it to be run once before any of the test methods in the class. The @BeforeClass methods of superclasses will be run before those the current class.

提交回复
热议问题