软件测试实验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)); } }
测试结果
单元测试覆盖测试
相关文章推荐
- 软件测试之实验一——如何使用JUnit,Hamcrest和Eclemma进行简单的软件测试
- 软件测试实验1
- 软件测试实验学习笔记系列6--图形界面测试(GUI)
- 软件测试lab1: 利用Junit, Hamcrest及Eclemma进行软件测试
- JAVA--第十一周实验--编写一个算术测试小软件
- 软件测试第一次实验
- 软件测试 第一次实验
- 软件测试实验学习笔记系列3--单元测试
- 软件测试实验——junit, hamcrest 和 eclemma的安装及使用
- 软件测试实验学习笔记系列4--CppUnit
- 软件测试实验学习笔记系列7--性能测试
- Puppet 实验五 软件安装测试
- 软件测试实验1
- 物理实验与软件测试
- 软件测试实验学习笔记系列5-单元覆盖测试
- 物理实验与软件测试
- 软件测试试验一实验总结
- 软件测试第一次实验/2016/3/18
- 软件测试实验学习笔记系列1