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时,先运行@Before10 @Before 11 public void before() {12 13 System.out.println("before");14 }15 16 //方法执行JUnit时,后运行@After17 @After18 public void after() {19 20 System.out.println("After");21 }22 23 //标注了@Test可以用JUnit测试24 @Test25 public void testRun() {26 27 Person t = new Person();28 29 //断言 其他返回值是1,就执行run();30 Assert.assertEquals("1", t.run());31 }32 33 @Test34 public void testEai() {35 Person t = new Person();36 37 t.eat();38 39 }40 41 }
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 }