標籤:
本次測試基於上次的對於單次輸入合法性測試的修改,對多個輸入的合法性同時測試
EDITBOX 文字框的非法輸入測試: 允許1到6個英文字元或數字,按OK檢測合法性並反饋。
按限制條件或規則的等價類別劃分方法劃分等價類別
| |
有效等價類別 |
無效等價類別 |
| 長度 |
1-6 |
0,7, … |
| 字元 |
A-Z,a-z,0-9 |
英文/數字以外字元,控制字元,標點符號
|
測試案例設計,根據有效和無效等價類別可以設計出測試案例
編號 |
輸入 |
預期輸出 |
實際輸出 |
Test1 |
null |
輸入含有非法字元 |
輸入含有非法字元 |
Test2 |
1352468 |
字元長度大於6 |
字元長度大於6 |
Test3 |
./147 |
輸入含有非法字元 |
輸入含有非法字元 |
Test4 |
Cpp111 |
OK! |
OK! |
Test5 |
[email protected]#$% |
輸入含有非法字元 |
輸入含有非法字元 |
Test6 |
123$^&* |
輸入含有非法字元 |
輸入含有非法字元 |
Test7 |
78%#% |
輸入含有非法字元 |
輸入含有非法字元 |
Test8 |
asdadasd |
字元長度大於6 |
字元長度大於6 |
Test9 |
aaaaa |
OK! |
OK! |
Test10 |
123123 |
OK! |
OK! |
輸出結果:
EventHandler部分代碼如下:
1 btn1.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>(){ 2 public void handle(MouseEvent event){ 3 String textString1 = textfield1.getText().toString(); 4 wordTesting(textString1,text1); 5 String textString2 = textfield2.getText().toString(); 6 wordTesting(textString2,text2); 7 String textString3 = textfield3.getText().toString(); 8 wordTesting(textString3,text3); 9 }10 });11 AnchorPane.setTopAnchor(hbox1, 40.0);12 AnchorPane.setLeftAnchor(hbox1, 60.0);13 AnchorPane.setTopAnchor(hbox2, 80.0);14 AnchorPane.setLeftAnchor(hbox2, 60.0);15 AnchorPane.setTopAnchor(hbox3, 120.0);16 AnchorPane.setLeftAnchor(hbox3, 60.0);17 AnchorPane.setTopAnchor(btn1, 180.0);18 AnchorPane.setRightAnchor(btn1, 150.0);19 root.getChildren().addAll(hbox1,hbox2,hbox3,btn1);20 primaryStage.setScene(new Scene(root, 380, 250));21 primaryStage.show();22 }23 private void wordTesting(String textString,Text textTesting)24 {25 char[] textChar = textString.toCharArray();26 27 if(textString.length()>6)28 textTesting.setText("字元長度大於6");29 else{30 for(int i=0;i<textString.length();i++)31 {32 if((textChar[i]>=‘0‘&&textChar[i]<=‘9‘)||33 (textChar[i]>=‘a‘&&textChar[i]<=‘z‘)||34 (textChar[i]>=‘A‘&&textChar[i]<=‘Z‘))35 textTesting.setText("OK!");36 else{37 textTesting.setText("輸入含有非法字元");38 break;39 }40 }41 }42 }
Rickie的軟體測試學習筆記-第三周