首页 > 代码库 > 点覆盖测试

点覆盖测试

一、测试环境

1.下载junit-4.12.jar和hamcrest-core-1.3.jar并直接在工程中导入。

2.下载eclemma,通过 help->Install new software ->添加站点 -> local,安装并重启即可,

二、测试程序

1.工程结构

技术分享

2.工程代码

Trianglejudge.java

package src;

public class Trianglejudge {
    public int getTriangle(int a,int b,int c){
        int TriangleKind = 3;
        if(a!=0&&b!=0&&c!=0){
            if(a==b&&b==c){
                TriangleKind = 0;
                return TriangleKind;
            }else if(a==b||b==c||a==c){
                TriangleKind = 1;
                return TriangleKind;
            }else{
                TriangleKind = 2;
                return TriangleKind;
            }
        }
        return TriangleKind;
    }
}

Trianglejudgetest.java

package src;

import static org.junit.Assert.*;

import org.junit.Test;

import junit.framework.TestCase;

public class TrianglejudgeTest extends TestCase{

    @Test
    public void testGetTriangle(){
        /*int a=1,b=1,c=1;
        
        int expResult = 0;
        int result = instance.getTriangle(a, b, c);
        assertEquals(expResult,result);*/
        int exp[] = {0,0,1,1,2,2,3,3};
        int a[] = {3,3,3,3,3,3,3,3};
        int b[] = {3,3,3,3,4,4,4,4};
        int c[] = {3,3,2,2,5,5,0,0};
        int result[]={0,0,0,0,0,0,0,0};
        for(int i=0;i<8;i++){
            Trianglejudge instance = new Trianglejudge();
            result[i] = instance.getTriangle(a[i], b[i], c[i]);
            assertEquals(exp[i],result[i]);
        }
    }
}

 

点覆盖测试