In Junit4, there are also Test Annotations: @ BeforeClass, @ Before, @ Test, @ After, @ AfterClass1, where: @ BeforeClass, @ AfterClass is newly added to Junit4. 2. If Run as ---> Junit Test runs the method containing @ Test annotations, all annotation methods will be executed, the execution sequence is: @ BeforeClass, @ Before, @ Test, @ After, @ AfterClass3. In JUnit4, if the Test class inherits the TestCase class, all Annotation functions. 4. Case: package cn.edu. hactcm. testjunit; import java. util. UUID; import org. junit. after; import org. junit. afterClass; import org. junit. before; import org. junit. beforeClass; import org. junit. test;/*** author: toto 11111111@qq.com * CFMS: Computer files management system * version: 1.0 01:26:04 ** methods used in unit test */public class TestJunit {private String flag;/*** run the command before loading the class, note that the Keyword: static */@ BeforeClass public static void testBeforeClass () {System. out. println ("public static void testBeforeClass ()");}/*** run the */@ Before public void testBefore () {System Before the target test method testTest. out. println ("-----------------------------------"); System. out. println ("public void testBefore ()"); flag = UUID. randomUUID (). toString (); System. out. println ("-----------------------------------");}/*** target Test method testTest () */@ Test public void testTest () {System. out. println ("public void testTest ()"); System. out. println (flag); flag = null;}/*** target Test method testTest2 () */@ Test public void testTest2 () {System. out. println ("public void testTest2 ()"); System. out. println (flag); flag = null;}/*** run the test method testTest () */@ After public void testAfter () {System. out. println ("-----------------------------------"); System. out. println ("public void testAfter ()"); System. out. println (flag); System. out. println ("---------------------------------");}/*** after loading this class, note that the Keyword: static */@ AfterClass public static void testAfterClass () {System. out. println ("public static void testAfterClass ()");} www.2cto.com} Only executes the testTest () method and the result is: public static void testBeforeClass () implements public void testBefore () export public void testTest () using ------------------------------------- public void testAfter () null ------------------------------------- public static void testAfterClass ()