• 软件测试(3)-基于等价类划分的一个小例子


     程序要求从一个输入框变为3个输入框,其他要求不变

     则这次的测试用例本着等价类划分的原则进行如下的修改

     表格旁边的就此这次的测试代码

    box No.1

    box No.2 box No.3 Result
    abc abc abc success
      abc abc box No.1 fail
    abc   abc box No.2 fail
    abc abc   box No.3 fail
    *1   abcdefgh All Fail
    abc *1 1bcedfgrt Only box No.1 success
    *7 abc   Only box No.2 success
      1 import javafx.application.Application;
      2 import javafx.event.ActionEvent;
      3 import javafx.event.EventHandler;
      4 import javafx.scene.Scene;
      5 import javafx.scene.control.Button;
      6 import javafx.scene.control.TextField;
      7 import javafx.scene.layout.AnchorPane;
      8 import javafx.scene.text.Text;
      9 import javafx.stage.Stage;
     10 
     11 
     12 public class Test extends Application{
     13     
     14     public static void main(String arg0[]){
     15         Test.launch(arg0);
     16     }
     17 
     18     public void start(Stage stage) throws Exception {
     19         stage.setTitle("Test One");
     20         AnchorPane root = new AnchorPane();
     21         
     22         Text text = new Text("请输入:");
     23         root.getChildren().add(text);
     24         AnchorPane.setTopAnchor(text, 45.0);
     25         AnchorPane.setLeftAnchor(text, 100.0);
     26         
     27         final TextField textInput1 = new TextField();
     28         root.getChildren().add(textInput1);
     29         AnchorPane.setTopAnchor(textInput1, 65.0);
     30         AnchorPane.setLeftAnchor(textInput1, 30.0);
     31         
     32         final TextField textInput2 = new TextField();
     33         root.getChildren().add(textInput2);
     34         AnchorPane.setTopAnchor(textInput2, 95.0);
     35         AnchorPane.setLeftAnchor(textInput2, 30.0);
     36         
     37         final TextField textInput3 = new TextField();
     38         root.getChildren().add(textInput3);
     39         AnchorPane.setTopAnchor(textInput3, 125.0);
     40         AnchorPane.setLeftAnchor(textInput3, 30.0);
     41         
     42         Button button = new Button();
     43         button.setText("确定");
     44         root.getChildren().add(button);
     45         AnchorPane.setTopAnchor(submit, 165.0);
     46         AnchorPane.setLeftAnchor(submit, 75.0);
     47         
     48         submit.setOnAction(new EventHandler<ActionEvent>() {
     49             public void handle(ActionEvent arg0) {
     50                 if(checkString(textInput1.getText().toString()) && checkString(textInput2.getText().toString()) && checkString(textInput3.getText().toString())){
     51                      Stage stage2 = new Stage();
     52                      AnchorPane root2 = new AnchorPane();
     53                      
     54                      Text result = new Text("三个输入框均符合要求~");
     55                      root2.getChildren().add(result);
     56                      AnchorPane.setTopAnchor(result, 50.0);
     57                      AnchorPane.setLeftAnchor(result, 50.0);
     58                      
     59                      stage2.setScene(new Scene(root2, 100, 100));
     60                      stage2.show();
     61                 }else if(checkString(textInput1.getText().toString()) && checkString(textInput2.getText().toString())){
     62                     Stage stage2 = new Stage();
     63                      AnchorPane root2 = new AnchorPane();
     64                      
     65                      Text result = new Text("第三个输入框不符合要求~");
     66                      root2.getChildren().add(result);
     67                      AnchorPane.setTopAnchor(result, 50.0);
     68                      AnchorPane.setLeftAnchor(result, 50.0);
     69                      
     70                      stage2.setScene(new Scene(root2, 100, 100));
     71                      stage2.show();
     72                 }else if(checkString(textInput1.getText().toString()) && checkString(textInput3.getText().toString())){
     73                     Stage stage2 = new Stage();
     74                      AnchorPane root2 = new AnchorPane();
     75                      
     76                      Text result = new Text("第二个输入框不符合要求~");
     77                      root2.getChildren().add(result);
     78                      AnchorPane.setTopAnchor(result, 50.0);
     79                      AnchorPane.setLeftAnchor(result, 50.0);
     80                      
     81                      stage2.setScene(new Scene(root2, 100, 100));
     82                      stage2.show();
     83                 }else if(checkString(textInput2.getText().toString()) && checkString(textInput2.getText().toString())){
     84                     Stage stage2 = new Stage();
     85                      AnchorPane root2 = new AnchorPane();
     86                      
     87                      Text result = new Text("第一个输入框不符合要求~");
     88                      root2.getChildren().add(result);
     89                      AnchorPane.setTopAnchor(result, 50.0);
     90                      AnchorPane.setLeftAnchor(result, 50.0);
     91                      
     92                      stage2.setScene(new Scene(root2, 100, 100));
     93                      stage2.show();
     94                 }else if(checkString(textInput1.getText().toString())){
     95                     Stage stage2 = new Stage();
     96                      AnchorPane root2 = new AnchorPane();
     97                      
     98                      Text result = new Text("只有第一个输入框符合要求~");
     99                      root2.getChildren().add(result);
    100                      AnchorPane.setTopAnchor(result, 50.0);
    101                      AnchorPane.setLeftAnchor(result, 50.0);
    102                      
    103                      stage2.setScene(new Scene(root2, 100, 100));
    104                      stage2.show();
    105                 }else if(checkString(textInput2.getText().toString())){
    106                     Stage stage2 = new Stage();
    107                      AnchorPane root2 = new AnchorPane();
    108                      
    109                      Text result = new Text("只有第二个输入框符合要求~");
    110                      root2.getChildren().add(result);
    111                      AnchorPane.setTopAnchor(result, 50.0);
    112                      AnchorPane.setLeftAnchor(result, 50.0);
    113                      
    114                      stage2.setScene(new Scene(root2, 100, 100));
    115                      stage2.show();
    116                 }else if(checkString(textInput3.getText().toString())){
    117                     Stage stage2 = new Stage();
    118                      AnchorPane root2 = new AnchorPane();
    119                      
    120                      Text result = new Text("只有第三个输入框符合要求~");
    121                      root2.getChildren().add(result);
    122                      AnchorPane.setTopAnchor(result, 50.0);
    123                      AnchorPane.setLeftAnchor(result, 50.0);
    124                      
    125                      stage2.setScene(new Scene(root2, 100, 100));
    126                      stage2.show();
    127                 }else{
    128                     Stage stage2 = new Stage();
    129                      AnchorPane root2 = new AnchorPane();
    130                      
    131                      Text result = new Text("三个输入框均不符合要求~");
    132                      root2.getChildren().add(result);
    133                      AnchorPane.setTopAnchor(result, 50.0);
    134                      AnchorPane.setLeftAnchor(result, 50.0);
    135                      
    136                      stage2.setScene(new Scene(root2, 100, 100));
    137                      stage2.show();
    138                 }
    139             }
    140         });
    141         
    142         stage.setScene(new Scene(root, 190,225));
    143         stage.show();
    144     }
    145     
    146     public boolean checkString(String str){
    147         if(str.length() == 0 || str.length() >= 7){
    148             return false;
    149         }
    150         
    151         char ch[] = new char[str.length()];
    152         ch = str.toCharArray();
    153         
    154         for(int i = 0; i < str.length(); i++){
    155             if((ch[i] >= 'a' && ch[i] <= 'z')||(ch[i] >= 'A' && ch[i] <= 'Z')||(ch[i] >= '0' && ch[i] <= '9'));
    156             else{
    157                 return false;
    158             }
    159         }
    160         return true;
    161     }
    162     
    163 }
  • 相关阅读:
    python函数续
    模拟数据库查询操作
    文件处理
    字符编码
    python函数
    ACM-ICPC 2018 南京赛区网络预赛Skr
    bzoj3676: [Apio2014]回文串 pam
    Wannafly挑战赛23B游戏
    bzoj4804: 欧拉心算 欧拉筛
    bzoj3884: 上帝与集合的正确用法 扩展欧拉定理
  • 原文地址:https://www.cnblogs.com/likuangge/p/4375966.html
Copyright © 2020-2023  润新知