實(shí)驗(yàn)04.使用基本路徑測(cè)試法求解“自動(dòng)售貨機(jī)”問(wèn)題.doc_第1頁(yè)
實(shí)驗(yàn)04.使用基本路徑測(cè)試法求解“自動(dòng)售貨機(jī)”問(wèn)題.doc_第2頁(yè)
實(shí)驗(yàn)04.使用基本路徑測(cè)試法求解“自動(dòng)售貨機(jī)”問(wèn)題.doc_第3頁(yè)
實(shí)驗(yàn)04.使用基本路徑測(cè)試法求解“自動(dòng)售貨機(jī)”問(wèn)題.doc_第4頁(yè)
實(shí)驗(yàn)04.使用基本路徑測(cè)試法求解“自動(dòng)售貨機(jī)”問(wèn)題.doc_第5頁(yè)
已閱讀5頁(yè),還剩6頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

實(shí)驗(yàn)報(bào)告實(shí)驗(yàn)序號(hào):04 實(shí)驗(yàn)項(xiàng)目名稱(chēng):使用基本路徑測(cè)試法求解 “自動(dòng)售貨機(jī)”問(wèn)題學(xué)號(hào)122姓名專(zhuān)業(yè)、班實(shí)驗(yàn)地點(diǎn)實(shí)1-511指導(dǎo)教師實(shí)驗(yàn)時(shí)間2013/4/27一、實(shí)驗(yàn)?zāi)康募耙髄 理解基本路徑覆蓋測(cè)試法的概念和方法;l 掌握使用Eclipse+JUnit+EclEmma進(jìn)行基本路徑覆蓋測(cè)試的方法。二、實(shí)驗(yàn)設(shè)備(環(huán)境)及要求l 開(kāi)發(fā)環(huán)境:Eclipse v3.7及以上版本;JUnit v4.10及以上版本;文本編輯軟件。 l 硬件要求:CPU PIV 以上,256M 內(nèi)存,1G 硬盤(pán)空間。l 系統(tǒng)要求:Windows98/Me/XP/NT/2000,IE 5 以上。三、實(shí)驗(yàn)內(nèi)容步驟1. 下載并安裝Eclipse+JUnit+EclEmma實(shí)驗(yàn)環(huán)境;2. 通讀自動(dòng)售貨機(jī)程序,并在Eclipse環(huán)境下運(yùn)行該程序;3. 使用基本路徑測(cè)試法設(shè)計(jì)測(cè)試用例,完成以下表格;編號(hào)輸入值Type輸入值money狀態(tài)預(yù)期輸出實(shí)際情況001Beer5C各資源剩余Input Information Type: Beer; Money: 5 Cents; Change: 0Current StateBeer: 5Orange Juice: 65 Cents: 71 Dollar: 6002OrangeJuice5C各資源剩余Input Information Type: OrangeJuice; Money: 5 Cents; Change: 0Current StateBeer: 6Orange Juice: 55 Cents: 71 Dollar: 6003Beer1D沒(méi)有啤酒Failure InformationBeer Shortage步驟:1、解壓eclemma軟件包,并放到eclipse安裝目錄的dropins文件夾下:2、重新啟動(dòng)eclipse軟件,菜單欄會(huì)出現(xiàn)新的圖標(biāo):3、查看Windows的Customize perspective項(xiàng)中的Command Groups Availabiity 多了Coverage項(xiàng):4、編寫(xiě)待測(cè)試類(lèi)SaleMachine.java文件和測(cè)試Junit Test Case文件SaleMachineTest.java:5、先點(diǎn)擊運(yùn)行看看,覆蓋了33.1%:6、分析:紅色代表未執(zhí)行、黃色代表?xiàng)l件沒(méi)有全部執(zhí)行、綠色代表執(zhí)行過(guò)了:7、繼續(xù)修改測(cè)試代碼,直到覆蓋率達(dá)到100%:共編寫(xiě)了12個(gè)測(cè)試用例,使待測(cè)試代碼100%被覆蓋,運(yùn)行如圖:四、實(shí)驗(yàn)結(jié)果與數(shù)據(jù)處理a、最終待測(cè)試代碼如下: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)/便于測(cè)試的初始化函數(shù)countOfFiveCents = fiveCents;countOfOneDollar = oneDollar;countOfBeer = numOfBeer;countOfOrangeJuice = numOfOrange;public String currentState()String state = Current Staten + Beer: + countOfBeer + n + Orange Juice: + countOfOrangeJuice + n + 5 Cents: + countOfFiveCents + n + 1 Dollar: + countOfOneDollar;return state;public String operation(String type, String money)/type是用戶(hù)選擇的產(chǎn)品,money是用戶(hù)投幣種類(lèi)if(money.equalsIgnoreCase(5C) /如果用戶(hù)投入5角錢(qián)if(type.equals(typeOfGoods0) /如果用戶(hù)選擇啤酒if(countOfBeer0) /如果還有啤酒countOfBeer-;countOfFiveCents+;resultOfDeal = Input Information n + Type: Beer; Money: 5 Cents; Change: 0nn + currentState();return resultOfDeal;elseresultOfDeal = Failure Information n + Beer Shortage;return resultOfDeal;else if (type.equals(typeOfGoods1) /用戶(hù)選擇橙汁if(countOfOrangeJuice 0)countOfOrangeJuice-;countOfFiveCents+;resultOfDeal = Input Information n + Type: OrangeJuice; Money: 5 Cents; Change: 0nn + currentState();return resultOfDeal;elseresultOfDeal = Failure Information n + OrangeJuice Shortage;return resultOfDeal;elseresultOfDeal = Failure Information n + Type Error;return resultOfDeal;else if(money.equalsIgnoreCase(1D) /如果用戶(hù)投入一元錢(qián)/if(countOfFiveCents0) /如果用戶(hù)投入一元錢(qián)/if(countOfFiveCents 0) /如果售貨機(jī)有零錢(qián)if(type.equals(typeOfGoods0)&countOfBeer0)/如果用戶(hù)選擇啤酒而且還有啤酒countOfBeer-;countOfFiveCents-;countOfOneDollar+;resultOfDeal = Input Information n + Type: Beer; Money: 1 Dollar; Change: 5 Centsnn + currentState();return resultOfDeal;else if (type.equals(typeOfGoods1)&countOfOrangeJuice0)/如果用戶(hù)選擇橙汁而且還有橙汁countOfOrangeJuice-;countOfFiveCents-;countOfOneDollar+;resultOfDeal = Input Information: n + Type: OrangeJuice; Money: 1 Dollar; Change: 5 Centsnn + currentState();return resultOfDeal;elseif(type.equals(typeOfGoods0)&countOfBeer=0) resultOfDeal = Failure Information n + Beer Shortage;return resultOfDeal;else if(type.equals(typeOfGoods1)&countOfOrangeJuice=0)resultOfDeal = Failure Information n + OrangeJuice Shortage;return resultOfDeal;elseresultOfDeal = Failure Information n + Type Error;return resultOfDeal;elseresultOfDeal = Failure Information n + Change Shortage;return resultOfDeal;/*elseresultOfDeal = Failure Information n + Money Error;return resultOfDeal;*/resultOfDeal = Failure Information n + Money Error;return resultOfDeal;b、最終測(cè)試代碼如下:import static org.junit.Assert.*;import org.junit.After;import org.junit.Before;import org.junit.Test;public class SaleMachineTest SaleMachine saleMachine = new SaleMachine();Beforepublic void setUp() throws Exception Afterpublic void tearDown() throws Exception Testpublic void testOperation1() String expectedResult = Input Information n +Type: OrangeJuice; Money: 5 Cents; Change: 0nn +Current Staten +Beer: 6n +Orange Juice: 5n +5 Cents: 7n +1 Dollar: 6;assertEquals(expectedResult, saleMachine.operation(OrangeJuice, 5C);Testpublic void testOperation2() String expectedResult = Input Information n +Type: Beer; Money: 5 Cents; Change: 0nn +Current Staten +Beer: 5n +Orange Juice: 6n +5 Cents: 7n +1 Dollar: 6;assertEquals(expectedResult, saleMachine.operation(Beer, 5C);Testpublic void testOperation3() SaleMachine saleMachine = new SaleMachine(6,6,0,6);String expectedResult = Failure Information n +Beer Shortage;assertEquals(expectedResult, saleMachine.operation(Beer, 5c);Testpublic void testOperation4() SaleMachine saleMachine = new SaleMachine(6,6,6,0);String expectedResult = Failure Information n +OrangeJuice Shortage;assertEquals(expectedResult, saleMachine.operation(OrangeJuice, 5c);Testpublic void testOperation5() SaleMachine saleMachine = new SaleMachine(6,6,6,6);String expectedResult = Failure Information n +Type Error;assertEquals(expectedResult, saleMachine.operation(apple, 5c);Testpublic void testOperation6() String expectedResult = Input Information n +Type: Beer; Money: 1 Dollar; Change: 5 Centsnn +Current Staten +Beer: 5n +Orange Juice: 6n +5 Cents: 5n +1 Dollar: 7;assertEquals(expectedResult, saleMachine.operation(Beer, 1D);Testpublic void testOperation7() String expectedResult = Input Information: n +Type: OrangeJuice; Money: 1 Dollar; Change: 5 Centsnn +Current Staten +Beer: 6n +Orange Juice: 5n +5 Cents: 5n +1 Dollar: 7;assertEquals(expectedResult, saleMachine.operation(OrangeJuice, 1D);Testpublic void testOperation8() SaleMachine saleMachine = new SaleMachine(6,6,0,6);String expectedResult = Failure Information n +Beer Shortage;assertEquals(expectedResult, saleMachine.operation(Beer, 1D);Testpublic void testOperation9() SaleMachine saleMachine = new SaleMachine(6,6,6,6);String expectedResult = Failure Information n +Type Error;assertEquals(expectedResult, saleMachine.operation(apple, 1D);Testpublic void testOperation10() SaleMachine saleMachine = new SaleMachine(6,6,6,0);String expectedResult = Failure Information n +Orang

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論