点覆盖测试
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了点覆盖测试相关的知识,希望对你有一定的参考价值。
一、测试环境
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]); } } }
以上是关于点覆盖测试的主要内容,如果未能解决你的问题,请参考以下文章