标签:nbsp str before mil eth 注意 常用 tab expect
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> </dependencies>
一个JUnit4的单元测试用例执行顺序为:
@BeforeClass -> @Before -> @Test -> @After -> @AfterClass
import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; public class Junit4Demo { // Run once, e.g. Database connection, connection pool @BeforeClass public static void runOnceBeforeClass() { System.out.println("@BeforeClass - runOnceBeforeClass"); } // Run once, e.g close connection, cleanup @AfterClass public static void runOnceAfterClass() { System.out.println("@AfterClass - runOnceAfterClass"); } // Should rename to @BeforeTestMethod // e.g. Creating an similar object and share for all @Test @Before public void runBeforeTestMethod() { System.out.println("@Before - runBeforeTestMethod"); } // Should rename to @AfterTestMethod @After public void runAfterTestMethod() { System.out.println("@After - runAfterTestMethod"); } @Test public void test_method_1() { System.out.println("@Test - test_method_1"); } @Test public void test_method_2() { System.out.println("@Test - test_method_2"); } }
输出:
@BeforeClass - runOnceBeforeClass @Before - runBeforeTestMethod @Test - test_method_1 @After - runAfterTestMethod @Before - runBeforeTestMethod @Test - test_method_2 @After - runAfterTestMethod @AfterClass - runOnceAfterClass
标签:nbsp str before mil eth 注意 常用 tab expect
原文地址:https://www.cnblogs.com/wwcom123/p/9092050.html