softwareTesting_work2_question2

  1. work2类
     package com.Phantom;
    
     import java.util.Scanner;
    
     import javax.print.DocFlavor.INPUT_STREAM;
    
     public class work2 {
    String str=null;
    StringBuffer re_str=null; public String getStr() {
    return str;
    } public void setStr(String str) {
    this.str = str;
    } public StringBuffer getRe_str() {
    return re_str;
    } public work2() {
    super();
    } public String input(){
    System.out.println("请输入内容:");
    //str = "how are you";
    String strs[] = str.split(" ");
    re_str = new StringBuffer();
    for(int i = strs.length-1; i >= 0; i--){
    //测试
    //System.out.println(strs[i]);
    re_str.append(" "+strs[i]);
    }
    System.out.println("输出:"+re_str);
    return re_str.toString();
    } }
  2. testing类
     package com.Phantom;
    
     import static org.junit.Assert.*;
    import junit.framework.TestCase; import org.junit.After;
    import org.junit.Before;
    import org.junit.Test; public class testing extends TestCase { private work2 w;
    @Before
    public void setUp() throws Exception {
    super.setUp();
    w=new work2();
    } @After
    public void tearDown() throws Exception {
    System.out.println("w.getStr()>>>"+w.getStr());
    System.out.println("w.getRe_str()>>>"+w.getRe_str());
    } @Test
    public void test() {
    // fail("Not yet implemented");
    w.setStr("as sa");
    w.input();
    assertTrue(w.getRe_str().toString()=="sa as");} }

junit

softwareTesting_work2_question2

覆盖率

softwareTesting_work2_question2

上一篇:设计模式——抽象工厂(Abstract Factory)


下一篇:1N系列稳压二极管参数