您的位置:首页 > 其它

软件测试实验LAB1

2018-03-21 22:41 465 查看

要求

在Eclipse中安装Junit 5, Hamcrest(1.3) 和Eclemma

1.在项目根目录下点击右键-> build path ->configure build path -> library 把junit.jar, hamcrest.jar添加进去

2.在Eclipse顶部菜单栏中 help->install new software,在add中输入Eclemma,点击Next,一步步按照提示,即可完成安装

程序

public class Triangle {
public int trian(int a,int b,int c){
if((a==b)&&(a==c)&&(b==c)){  //等边
return 0;
}
else if((a!=b)&&(a!=c)&&(b!=c)){  //不等边
return 1;
}
else{
return 2;      //等腰
}
}
}


测试代码:

import java.util.Arrays;

import java.util.Collection;

import org.junit.*;

import org.junit.runner.RunWith;

import org.junit.runners.Parameterized;

import org.junit.runners.Parameterized.Parameters;

import static org.junit.Assert.*;

@RunWith(Parameterized.class)

public class triangleTest {

private Triangle tr;

private int a,b,c,expected;

public triangleTest(int a,int b,int c,int expected){

this.a=a;

this.b=b;

this.c=c;

this.expected=expected;

}

@Before

public void setUp(){

tr=new Triangle();

}

@Parameters  //给构造函数参数初始化

public static Collection<Object[]> getData(){

return Arrays.asList(new Object[][]{

{1,2,3,1},

{3,3,3,0},

{2,2,4,2},

{2,3,4,1}

});

}

@Test     //测试函数

public void testTrian(){
assertEquals(this.expected,tr.trian(a,b,c));
}
}


测试结果

单元测试



覆盖测试


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: