第二次作业+105032014117
1.测试帖链接
http://www.cnblogs.com/youfanxian/p/6607540.html
2.测试人员提出的问题、发现的缺陷
没有对非整数输入进行判断。用例1,2可以明显看出程序不支持字符的输入,并且会使程序崩溃
建议输入条件判断语句判断是否非数字,否则会造成程序崩溃重复执行代码
3.修正后的代码清单
1 package Test01; 2 import java.util.Scanner; 3 4 public class Test01 { 5 public static void main(String[] args) { 6 String[] num=new String[3]; 7 Scanner input = new Scanner(System.in); 8 boolean flag=true; 9 while(flag){ 10 System.out.print("请分别输入三种手机配件的销售情况:"); 11 num[0] = input.next(); 12 num[1] = input.next(); 13 num[2] = input.next(); 14 int headphone, shell, protector; 15 if (isNumeric(num[0]) && isNumeric(num[1]) && isNumeric(num[2])) 16 { 17 headphone = change(num[0]); 18 shell = change(num[1]); 19 protector = change(num[2]); 20 commission(headphone, shell, protector); 21 } 22 else 23 { 24 System.out.println("输入数量不满足要求,返回重新输入"); 25 }} 26 } 27 public static boolean isNumeric(String str){ 28 for (int i = str.length();--i>=0;){ 29 if (!Character.isDigit(str.charAt(i))){ 30 return false; 31 } 32 } 33 return true; 34 } 35 public static int change(String str) 36 { 37 int a=Integer.parseInt(str); 38 return a; 39 } 40 static float commission(int headphone, int shell, int protector) 41 { 42 float paymoney = 0; 43 int total = headphone * 80 + shell * 10 + protector * 8; 44 if (headphone < 0 || shell < 0 || protector < 0) 45 { 46 System.out.println("输入数量不满足要求”,返回重新输入"); 47 } 48 else if (total < 1000) 49 { 50 paymoney = (float) (total*0.1); 51 System.out.println("佣金为:"+paymoney); 52 } 53 else if (total >= 1000 && total <=1800) 54 { 55 paymoney = (float) ((total - 1000)*0.15 + 100); 56 System.out.println("佣金为:"+paymoney); 57 } 58 else if (total>1800) 59 { 60 paymoney = (float) ((total - 1800)*0.2 + 220); 61 System.out.println("佣金为:"+paymoney); 62 } 63 return paymoney; 64 } 65 }
4.修正后心得体会
针对缺陷增加了两个函数,一个用来检查输入字符串是否为数字,一个用来将字符串转化为整形。
缺陷原因在于对问题分析的不够严谨,没有考虑到用户的非法输入。
白盒测试并不是简单的按照代码设计用例,而是需要根据不同的测试需求,结合不同的测试对象,使用适合的方法进行测试。因为对于不同复杂度的代码逻辑,可以衍生出许多种执行路径,只有适当的测试方法,才能帮助我们从代码的迷雾森林中找到正确的方向。
语句覆盖主要特点:语句覆盖是最起码的结构覆盖要求,语句覆盖要求设计足够多的测试用例,使得程序中每条语句至少被执行一次。
条件覆盖主要特点:条件覆盖要求设计足够多的测试用例,使得判定中的每个条件获得各种可能的结果,即每个条件至少有一次为真值,有一次为假值。
路径覆盖主要特点:设计足够的测试用例,覆盖程序中所有可能的路径。

浙公网安备 33010602011771号