- work2类
1 package com.Phantom; 2 3 import java.util.Scanner; 4 5 import javax.print.DocFlavor.INPUT_STREAM; 6 7 public class work2 { 8 String str=null; 9 StringBuffer re_str=null; 10 11 public String getStr() { 12 return str; 13 } 14 15 public void setStr(String str) { 16 this.str = str; 17 } 18 19 public StringBuffer getRe_str() { 20 return re_str; 21 } 22 23 public work2() { 24 super(); 25 } 26 27 public String input(){ 28 System.out.println("请输入内容:"); 29 //str = "how are you"; 30 String strs[] = str.split(" "); 31 re_str = new StringBuffer(); 32 for(int i = strs.length-1; i >= 0; i--){ 33 //测试 34 //System.out.println(strs[i]); 35 re_str.append(" "+strs[i]); 36 } 37 System.out.println("输出:"+re_str); 38 return re_str.toString(); 39 } 40 41 }
- testing类
1 package com.Phantom; 2 3 import static org.junit.Assert.*; 4 import junit.framework.TestCase; 5 6 import org.junit.After; 7 import org.junit.Before; 8 import org.junit.Test; 9 10 public class testing extends TestCase { 11 12 private work2 w; 13 @Before 14 public void setUp() throws Exception { 15 super.setUp(); 16 w=new work2(); 17 } 18 19 @After 20 public void tearDown() throws Exception { 21 System.out.println("w.getStr()>>>"+w.getStr()); 22 System.out.println("w.getRe_str()>>>"+w.getRe_str()); 23 } 24 25 @Test 26 public void test() { 27 // fail("Not yet implemented"); 28 w.setStr("as sa"); 29 w.input(); 30 assertTrue(w.getRe_str().toString()=="sa as");} 31 32 }
junit
覆盖率