




版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上實驗報告實驗序號:02實驗項目名稱:基本路徑測試法和單元測試工具JUnit的使用學號姓名曹鋒專業(yè)、班09軟件工程一班實驗地點1#316指導教師崔建峰實驗時間2012/3/5一、實驗目的l 掌握基本路徑測試方法;l 了解在Eclipse環(huán)境下JUnit單元測試工具的安裝和使用方法;l 針對一個實際問題,在JUnit環(huán)境下設計并執(zhí)行測試用例。二、實驗要求l 開發(fā)環(huán)境:Eclipse v3.7及以上版本;JUnit v4.10及以上版本;文本編輯軟件。 l 硬件要求:CPU PIV 以上,256M 內(nèi)存,1G 硬盤空間。l 系統(tǒng)要求:Windows98/Me/XP/NT/2
2、000,IE 5 以上。三、實驗內(nèi)容與步驟1. 下載并安裝JDK+Eclipse,學習Eclipse安裝與使用方法。2. 下載并安裝JUnit,學習JUnit安裝與使用方法。3. 通讀自動售貨機程序,并將其在Eclipse環(huán)境下運行。問題描述,程序流程圖和程序源代碼見附錄。4. 按照如下格式,采用基本路徑測試法編寫測試用例(要有程序流程控制圖,基本路徑)。編號輸入值Type輸入值money狀態(tài)預輸出實際情況1Beer5C各資源剩余Input Information Type: Beer; Money: 5 Cents; Change: 0Current StateBeer: 5Orange J
3、uice: 65 Cents: 71 Dollar: 6與預期相同2OrangeJuice5C各資源剩余Input Information Type: OrangeJuice; Money: 5 Cents; Change: 0Current StateBeer: 6Orange Juice: 55 Cents: 71 Dollar: 6與預期相同3Beer5C沒有啤酒Filure InformationBeer Shortage與預期相同4OrangeJuice5C沒有橙汁Failure InformationOrangeJuice Shortage與預期不同5Cola5C各資源剩余Fail
4、ure InformationType Error與預期相同6Beer1D沒啤酒Failure InformationBeer Shortage與預期不同7Beer1D各資源剩余Input Information Type: Beer; Money: 1 Dollar; Change:5 CentsCurrent StateBeer: 5Orange Juice: 65 Cents: 51 Dollar: 7與預期不同8OrangeJuice1D各資源剩余Input Information Type: OrangeJuice; Money: 1 Dollar; Change: 5 CentsC
5、urrent StateBeer: 6Orange Juice: 55 Cents:51 Dollar: 7與預期不同9OrangeJuice1D沒有橙汁Failure InformationOrangeJuice Shortage與預期不同10Cola1D各資源剩余Failure InformationType Error與預期相同11Beer1D沒有5角Failure InformationChange Shortage與預期不同12OrangeJuice4C各資源剩余Failure InformationMoney Error與預期相同5. 編寫并執(zhí)行基于JUnit的測試用例。6. 提交
6、測試用例程序和該程序運行結果最終畫面。7. 總結本次試驗,并撰寫實驗報告。程序流程圖如圖一所示:(流程圖可復制粘貼到畫圖查看大圖。)圖一實驗截圖:編寫完測試用例,運行程序,源程序有六個錯誤,如圖二所示:圖二根據(jù)相應錯誤修改代碼后測試通過,如圖三所示:圖三四、分析與討論 通過此次實驗,我初步學會了測試工具Junit的使用方法,發(fā)現(xiàn)使用測試工具可以給程序測試帶來很大的方便,使我們更容易找到程序的錯誤。五、教師評語簽名:日期:成績程序源代碼:修改后的代碼:package first;public class SaleMachine private int countOfBeer, countOfOr
7、angeJuice, 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
8、, int numOfBeer, int numOfOrange)/便于測試的初始化函數(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: + cou
9、ntOfFiveCents + n + 1 Dollar: + countOfOneDollar;return state;public String operation(String type, String money)/type是用戶選擇的產(chǎn)品,money是用戶投幣種類if(money.equalsIgnoreCase(5C) /如果用戶投入5角錢if(type.equals(typeOfGoods0) /如果用戶選擇啤酒if(countOfBeer0) /如果還有啤酒countOfBeer-;countOfFiveCents+;resultOfDeal = Input Informat
10、ion n + Type: Beer; Money: 5 Cents; Change: 0nn + currentState();return resultOfDeal;elseresultOfDeal = Failure Information n + Beer Shortage;return resultOfDeal;else if (type.equals(typeOfGoods1) /用戶選擇橙汁if(countOfOrangeJuice 0)countOfOrangeJuice-;countOfFiveCents+;resultOfDeal = Input Information n
11、 + 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) /如果用戶投入一元錢/if(countO
12、fFiveCents0) /如果用戶投入一元錢/if(countOfFiveCents 0) /如果用戶有零錢if(type.equals(typeOfGoods0)&countOfBeer0)/如果用戶選擇啤酒而且還有啤酒countOfBeer-;countOfFiveCents-;countOfOneDollar+;resultOfDeal = Input Information n + Type: Beer; Money: 1 Dollar; Change: 5 Centsnn + currentState();return resultOfDeal;else if (type.equa
13、ls(typeOfGoods1)&countOfOrangeJuice0)/如果用戶選擇橙汁而且還有橙汁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 =
14、 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 Infor
15、mation n + Change Shortage;return resultOfDeal;/else/resultOfDeal = Failure Information n + Money Error;/return resultOfDeal;/resultOfDeal = Failure Information n + Money Error;return resultOfDeal;測試用例代碼:package first;import junit.framework.TestCase;public class TestSaleMachine extends TestCase publ
16、ic void testOperation1() /售貨機各資源均有剩余,用戶投幣5角,選擇啤酒SaleMachine saleMachine1 = new SaleMachine();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, saleMachine1.operation(
17、Beer, 5C);public void testOperation2()/售貨機沒有啤酒剩余,用戶投幣5角,選擇啤酒SaleMachine saleMachine2 = new SaleMachine(6,6,0,6);String expectedResult = Failure Information n + Beer Shortage;assertEquals(expectedResult,saleMachine2.operation(Beer, 5C);public void testOperation3() /售貨機各資源均有剩余,用戶投幣5角,選擇橙汁SaleMachine s
18、aleMachine3 = new SaleMachine();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, saleMachine3.operation(OrangeJuice, 5C);public void testOperation4()/售貨機沒有橙汁,
19、用戶投幣5角,選擇橙汁SaleMachine saleMachine4 = new SaleMachine(6,6,6,0);String expectedResult = Failure Information n + OrangeJuice Shortage;assertEquals(expectedResult,saleMachine4.operation(OrangeJuice, 5C);public void testOperation5()/用戶投入5角,選擇非啤酒非橙汁SaleMachine saleMachine5 = new SaleMachine(6,6,6,6);Stri
20、ng expectedResult = Failure Information n + Type Error;assertEquals(expectedResult,saleMachine5.operation(Cola, 5C);public void testOperation6()/售貨機有啤酒且有5角幣,用戶投幣1元,選擇啤酒SaleMachine saleMachine6 = new SaleMachine(6,6,6,6);String expectedResult = Input Information n +Type: Beer; Money: 1 Dollar; Change
21、: 5 Centsnn +Current Staten +Beer: 5n +Orange Juice: 6n +5 Cents: 5n +1 Dollar: 7;assertEquals(expectedResult,saleMachine6.operation(Beer, 1D);public void testOperation7() /售貨機沒有啤酒有5角,用戶投幣1元,選擇啤酒SaleMachine saleMachine7 = new SaleMachine(6,6,0,6);String expectedResult = Failure Information n + Beer
22、Shortage;assertEquals(expectedResult, saleMachine7.operation(Beer, 1D);public void testOperation8()/售貨機有橙汁且有5角幣,用戶投幣1元,選擇橙汁SaleMachine saleMachine8 = new SaleMachine(6,6,6,6);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,saleMachine8.operation(OrangeJuice, 1D);public void testOperation9()/售貨機有5角沒有橙汁,用戶投幣1元,選擇橙汁SaleMachine saleMachine9 = new SaleMachine(6,6,6,0);String expectedResult = Failure Information n + OrangeJu
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 產(chǎn)品特性分析培訓
- 中小學生心理健康教育整體方案
- 代駕安全責任協(xié)議書
- 鏟車銷售、維修與保養(yǎng)服務合同
- 燒烤連鎖品牌加盟管理合同
- 房地產(chǎn)開發(fā)企業(yè)財務代理記賬及土地增值稅合同
- 礦山安全標志牌設計制作及銷售合同
- 車輛保養(yǎng)與道路救援服務合作協(xié)議
- 離婚時遺產(chǎn)繼承與財產(chǎn)分割協(xié)議書
- 茶葉拍賣會組織與委托合同
- 礦井調(diào)度員考試題及答案
- 美國《GENIUS法案》:合規(guī)穩(wěn)定幣的監(jiān)管框架
- 2025至2030中國控制按鈕開關行業(yè)產(chǎn)業(yè)運行態(tài)勢及投資規(guī)劃深度研究報告
- 臨商銀行股份有限公司招聘筆試真題2024
- 2025廣東高考物理試題(大題部分)+評析
- DB31-T 1593-2025 基于自動駕駛功能的公交運營技術要求
- 醫(yī)院純水系統(tǒng)管理制度
- 2025年中考英語考前沖刺押題模擬試卷 3套(含答案)
- 鄉(xiāng)村基層工作筆試題目及答案
- CJ/T 258-2014纖維增強無規(guī)共聚聚丙烯復合管
- 2025年小升初語文復習:積累運用 專項匯編(含答案)
評論
0/150
提交評論