软件测试实验1
2018-03-23 19:58
267 查看
实验要求
Install Junit(4.12), Hamcrest(1.3) with EclipseInstall Eclemma with Eclipse
Write a java program for the triangle problem and test the program with Junit.
Description of triangle problem:
Function triangle takes three integers a,b,c which are length of triangle sides; calculates whether the triangle is equilateral, isosceles, or scalene.
实际操作
首先需要翻墙下载junit(4.12)和Hamcrest-all(1.3)然后打开eclipse,新建一个java的project,右键properties-Java Build Path-Library-Add External JARs
安装eclemma (这是一个开源的软件测试工具,可以查看代码调用情况、也可以检测单覆盖率)
选择Help->Eclipse Marketplace->搜索eclemma,Install
重启eclipse发现工具栏上出现Coverage图标,说明安装成功
可以开始编码写程序了。
lab1.Main
package lab1; public class Main { //whether this three integers can make a triangle public Boolean triangle(int a,int b,int c) { if(a <= 0 || b <= 0 || c <= 0 || a+b <= c || a+c <= b || b+c <= a) return false; return true; } public Boolean equilateral(int a,int b,int c) { if(triangle(a,b,c) && a == b && b == c) return true; return false; } public Boolean isosceles(int a,int b,int c) { if(triangle(a,b,c) && (a == b || b == c || a == c) ) return true; return false; } /* * 0 not a triangle * 1 equilateral * 2 isosceles * 3 triangle */ public int tri(int a,int b,int c) { if(!triangle(a,b,c)) return 0; if(equilateral(a,b,c)) return 1; if(isosceles(a,b,c)) return 2; return 3; } public static void main(String[] args) { } }
右键new一个junit Test case,进行测试。
MainTest
package lab1; import static org.junit.Assert.*; import org.junit.Test; public class MainTest { /* * 0 not a triangle * 1 equilateral * 2 isosceles * 3 triangle */ @Test public void test() { Main l = new Main(); assertEquals(0,l.tri(-2, 3, 32)); assertEquals(0,l.tri(2, 3, 32)); assertEquals(0,l.tri(0, 0, 1)); assertEquals(0,l.tri(0, 0, 0)); assertEquals(0,l.tri(-2, -2, -2)); assertEquals(1,l.tri(3, 3, 3)); assertEquals(2,l.tri(8, 6, 6)); assertEquals(2,l.tri(2, 3, 2)); assertEquals(2,l.tri(2, 1, 2)); assertEquals(3,l.tri(2, 3, 4)); assertEquals(3,l.tri(2, 5, 6)); assertEquals(3,l.tri(3, 4, 5)); } }
测试结果:
绿色为访问到了,黄色为部分访问,红色为未访问到。相关文章推荐
- 软件测试实验学习笔记系列7--性能测试
- 软件测试上机实验(一)
- 软件测试实验1
- 软件测试实验报告
- 物理实验与软件测试
- 软件测试:黑盒测试实验报告及感想
- 实验用协议软件测试、调试说明(一)
- 软件测试实验学习笔记系列5-单元覆盖测试
- 软件测试试验一实验总结
- 软件测试第一次实验/2016/3/18
- 在Eclipse下,采用mulan多标签分类软件进行一个简单的测试实验
- 软件测试技术,软件项目管理 实验时间安排 2009春季
- 2010年春季 软件测试技术 软件项目管理 实验安排
- 软件测试实验学习笔记系列1
- 软件测试实验一
- 山东大学软件测试技术实验三报告
- 软件测试实验一,人民币大小写黑盒测试报告
- JAVA--第十一周实验--编写一个算术测试小软件
- 软件测试实验学习笔记系列2 -- lint,splint的使用