1 import junit.framework.Assert;
2
3 import org.junit.After;
4 import org.junit.Before;
5 import org.junit.Test;
6
7 public class JUnitTest {
8
9 //方法执行JUnit时,先运行@Before
10 @Before
11 public void before() {
12
13 System.out.println("before");
14 }
15
16 //方法执行JUnit时,后运行@After
17 @After
18 public void after() {
19
20 System.out.println("After");
21 }
22
23 //标注了@Test可以用JUnit测试
24 @Test
25 public void testRun() {
26
27 Person t = new Person();
28
29 //断言 其他返回值是1,就执行run();
30 Assert.assertEquals("1", t.run());
31 }
32
33 @Test
34 public void testEai() {
35 Person t = new Person();
36
37 t.eat();
38
39 }
40
41 }