junit测试框架

 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 }
View Code
 1 public class Person {
 2 
 3     public String run(){
 4         
 5         System.out.println("run");
 6         
 7         return "1";
 8     }
 9     
10     public void eat(){
11         
12         System.out.println("eai");
13     }
14 
15 }
View Code

 

posted @ 2014-06-14 20:12  是但哥  阅读(162)  评论(0)    收藏  举报