结对项目——fault,error,failure的程序设计

一.结对编程内容:

  1.不能触发Fault。

  2.触发Fault,但是不触发Error。

  3.触发Error,但不触发Failure。

二.结对编程人员

  1.周宗耀、周浩;

  2.结对截图:

 

 

 

 

三.结对项目编程

  1.不能触发Fault:

 1 package com.hao_mini.www;
 2 
 3 import java.util.Scanner;
 4 
 5 public class True {
 6 
 7 public static void main(String[] args) {
 8 Scanner in=new Scanner(System.in);
 9 int i=in.nextInt();
10 int[] TrueArray=new int[i];
11 for(int j=0;j<TrueArray.length;j++){
12 TrueArray[j]=in.nextInt();
13 }
14 for(int j=0;j<TrueArray.length;j++){
15 System.out.println(TrueArray[j]);
16 }
17 in.close();
18 }
19 
20 }

  

2.触发Fault,但是不触发Error:

 1 package com.hao_mini.www;
 2 
 3 import java.util.Scanner;
 4 
 5 public class Nofault {
 6 public static void main(String[] args) {
 7 Scanner in=new Scanner(System.in);
 8 int i;
 9 i=in.nextInt();
10 int counti=0;
11 for(int j=1;j<i;j++){
12 counti++;
13 }
14 System.out.println(counti);
15 in.close();
16 }
17 }

 

 分析:在11行  for(int j=1;j<i;j++){  触发了Fault,但并未造成Error。

  3.触发Error,但不触发Failure:

 1 package com.hao_mini.www;
 2 
 3 import java.util.Scanner;
 4 
 5 public class HaveFaultNotError {
 6 
 7 public static void main(String[] args) {
 8 Scanner in=new Scanner(System.in);
 9 
10 System.out.println("请输入长度");
11 int i=in.nextInt();
12 int[] TestArray=new int[i];
13 int sum=0,j=0;
14 for(;j<TestArray.length-1;j++){
15 TestArray[j]=in.nextInt();
16 sum+=TestArray[j];
17 }
18 int avg=sum/j;
19 System.out.println("avg="+avg);
20 in.close();
21 }
22 
23 }

  分析:在 14 行到17行  for(;j<TestArray.length-1;j++){ }处存在Error,并且触发了Error(sum=6 预期中间变量sum=9) , Failure((预期avg=sum(9)/3=3)

实际avg=sum(6)/2)  未触发。

四.分析与总结

  在这次结对中,更深入的理解了fault、error和failure的意义以及这三者的关系。同時,实践了代码测试,对如何有效地测试有了一定的了解并增加了我们对测试的兴趣。

原文地址:https://www.cnblogs.com/zzy567/p/5409515.html