標籤:
必做一:
針對附錄1給出的三角形判斷Java 代碼,應用等價類別劃分法設計測試案例,用表格形式列出設計的測試案例:
測試案例如下:(紅色字型為錯誤預言)
| 序號 |
測試輸入:三條邊 |
測試預言:【Oracle:Illegal(非三角形),Scalene(一般三角形), Isoceles(等腰三角形),Regular(等邊三角形)】 |
| 1 |
(5,5,5) |
Regular |
| 2 |
(-5,-5,-5) |
Regular |
| 3 |
(1,4,5) |
Illegal |
| 4 |
(2,3,5) |
Illegal |
| 5 |
(3,4,5) |
Scalene |
| 6 |
(4,5,8) |
Scalene |
| 7 |
(4,4,8) |
Isoceles |
| 8 |
(4,4,9) |
Isoceles |
必做2:模仿附錄2給出的三角形判斷Junit測試代碼,設計單元測試指令碼,測試 必做一設計得到的測試案例。注意測試指令碼中測試案例出現順序
與[必做一表格所列順序一致。運行所得的測試指令碼,截運行結果圖,寫到部落格中,同時將原始碼push到你自己的github
根據測試案例,測試部分代碼如下:
@Test public void testTriangle1() { Triangle t = new Triangle(5,5,5); assertFalse(t.isTriangle(t)); } @Test public void testIsTriangle2(){ // according to the mutant, this test case should fail Triangle t = new Triangle(-5,-5,-5); assertFalse(t.isTriangle(t)); } @Test public void testIsTriangle3(){ // according to the mutant, this test case should fail Triangle t = new Triangle(1,4,5); assertFalse(t.isTriangle(t)); } @Test public void testIsTriangle4(){ // according to the mutant, this test case should fail Triangle t = new Triangle(2,3,5); assertFalse(t.isTriangle(t)); }
測試結果如下:
必做三: 心得體會,寫下本次練習你收穫的知識點(PS:測試案例設計方法和步驟;測試指令碼設計步驟或主要內容)
在設計測試案例,等價劃分可以分為四類:非三角形,一般三角形,等腰三角形和等邊三角形。在設計測試資料時,
要注意一些特殊資料的測試,我使用了(-5,-5,-5)等。由於上課就沒有搞明白,對java的使用能力也有限,結果
在測試環節費了很大的力,好在之前結對程式設計時我的搭檔對這個還略有研究,請教了別人只後終於能夠搞清楚這裡的關鍵
這裡我使用的是Junit 4。在測試之前要註明@test,其實在匯入test時會有但是不能刪掉它,我覺得這次最大的收穫就是
懂得使用Junit來進行一般的測試,在eclipse中使用Junit4進行單元測試,也明白了一個程式不是能運行就是完成了而是要
經過各種測試才是一個完整正確的代碼。
完整代碼上傳至github:https://github.com/superyy
作業八——單元測試練習(個人練習)