软件测试第一次上机实验报告

软件测试第一次上机实验作业

软件三班 马铖明 3014218127

1.Install Junit(4.12), Hamcrest(1.3) with Eclipse

          

2.Install Eclemma with Eclipse

          

3.Write a java program for the triangle problem and test the program with Junit. 

   (1)下载Junit和hamcrest完成后,在新建的项目中导入这两个jar包,但是要注意这两个包保存在同一个文件夹中

           

   (2)在项目中新建与src同级的source folder,命名为test,两个文件夹下新建class,package统一命名为junit2017,src目录下的class文件名为calculate.java,test目录下的class文件名为testcal.java。

           

 (3)calculate.java & testcal.java program

        calculate.java

package junit2017;

public class calculate {
    private static int result = 0;
    public void triangle(int a,int b,int c)
    {
        if(a<=0 || b<=0 || c<=0)
        {
            result = 0;
        }
        else
        {
            if(((a+b)>c) && ((a+c)>b && (b+c)>a))
            {
                if((a == b) &&(a == c))
                {
                  result = 3;
                }
                if((a==b && a!=c)||(a==c && a!=b)||(b==c && a!=b))
                {
                    result = 2;
                }
                if(a!=b && a!=c && b!=c)
                {
                    result = 1;
                }
            }
            else
            {
                result = 0;
            }
        }
        
    }
    public int getReuslt(){
        return result;
    }
    
        public void clear(){
        result = 0;
    }

}

       testcal.java

package junit2017;

import static org.junit.Assert.*;
import org.junit.Test;
public class testcal {
    
    private static calculate cal = new calculate();
    @Test
    public void testTriangle(){
        
    cal.triangle(5, 5, 5);
    assertEquals(3, cal.getReuslt());
    cal.triangle(5, 5, 6);
    assertEquals(2, cal.getReuslt());
    cal.triangle(3, 4, 5);
    assertEquals(1, cal.getReuslt());
    cal.triangle(12, 5, 5);
    assertEquals(0, cal.getReuslt());
    }
    

}

(4)测试结果

         

       

       

posted on 2017-03-10 13:24  不睡懒觉  阅读(284)  评论(0编辑  收藏  举报

导航