白盒测试实验报告

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

《软件测试技术》实验报告

实验序号:03 实验项目名称:使用基本路径覆盖法测试自动售货机程序

修改代码后:

五、分析与讨论

这次试验基于上次的试验,围绕白盒测试的基本路径覆盖法测试进行测试。重点在于对测试用例的设计,试验中借助了程序流程控制图来设计用例。

附件:

修改后的实现代码:

package test3;

public class SaleMachine {

private int countOfBeer, countOfOrangeJuice, countOfFiveCents, countOfOneDollar;

private String[] typeOfGoods = {"Beer", "OrangeJuice"};

private String resultOfDeal;

public SaleMachine()

{

initial();

}

public void initial()

{

countOfBeer = 6;

countOfOrangeJuice = 6;

countOfFiveCents = 6;

countOfOneDollar = 6;

}

public SaleMachine(int fiveCents, int oneDollar, int numOfBeer, int numOfOrange)

//便于测试的初始化函数

{

countOfFiveCents = fiveCents;

countOfOneDollar = oneDollar;

countOfBeer = numOfBeer;

countOfOrangeJuice = numOfOrange;

}

public String currentState()

{

String state = "Current State\n" +

"Beer: " + countOfBeer + "\n" +

"Orange Juice: " + countOfOrangeJuice + "\n" +

"5 Cents: " + countOfFiveCents + "\n" +

"1 Dollar: " + countOfOneDollar;

return state;

}

public String operation(String type, String money)

//type是用户选择的产品,money是用户投币种类

{

if(money.equalsIgnoreCase("5C")) //如果用户投入5角钱

{

if(type.equals(typeOfGoods[0])) //如果用户选择啤酒

{

if(countOfBeer>0) //如果还有啤酒

{

countOfBeer--;

countOfFiveCents++;

resultOfDeal = "Input Information \n" +

"Type: Beer; Money: 5 Cents; Change: 0\n\n" + currentState();

return resultOfDeal;

}

else

{

resultOfDeal = "Failure Information \n" + "Beer Shortage";

return resultOfDeal;

}

}

else if (type.equals(typeOfGoods[1])) //用户选择橙汁

{

if(countOfOrangeJuice > 0)

{

countOfOrangeJuice--;

countOfFiveCents++;

resultOfDeal = "Input Information \n" +

"Type: OrangeJuice; Money: 5 Cents; Change: 0\n\n" + currentState();

return resultOfDeal;

}

else

{

resultOfDeal = "Failure Information \n" + "OrangeJuice Shortage";

return resultOfDeal;

}

}

else

{

resultOfDeal = "Failure Information \n" + "Type Error";

return resultOfDeal;

}

}

else if(money.equalsIgnoreCase("1D")) //如果用户投入一元钱

{

if(countOfFiveCents > 0) //如果用户有零钱

{

if(type.equals(typeOfGoods[0])&&countOfBeer>0)//如果用户选择啤酒而且还有啤酒

{

countOfBeer--;

countOfFiveCents--;

countOfOneDollar++;

resultOfDeal = "Input Information \n" +

"Type: Beer; Money: 1 Dollar; Change: 5 Cents\n\n" + currentState();

return resultOfDeal;

}

else if (type.equals(typeOfGoods[1])&&countOfOrangeJuice>0)//如果用户选择橙汁而且还有橙汁

{

countOfOrangeJuice --;

countOfFiveCents --;

countOfOneDollar ++;

resultOfDeal = "Input Information \n" +

"Type: OrangeJuice; Money: 1 Dollar; Change: 5 Cents\n\n" + currentState();

return resultOfDeal;

}

else

{

if(type.equals(typeOfGoods[0])&&countOfBeer<=0)

{

resultOfDeal = "Failure Information \n" + "Beer Shortage";

return resultOfDeal;

}

else

if(type.equals(typeOfGoods[1])&&countOfOrangeJuice<=0)

{

resultOfDeal = "Failure Information \n" + "OrangeJuice Shortage";

return resultOfDeal;

}

else

相关文档
最新文档