zoukankan      html  css  js  c++  java
  • 黑盒测试的等价类划分法软件测试(2)

      相对于只需要输入一个信息的输入框,在填写资料的时候我们往往需要同时输入多个信息,且必须同时符合输入要求。

      在原有的输入框中增加输入要求,将输入增加到三个,有一个以上的非法输入即判断不成果,只有三个输入均正确时判定为输入成功。

      等价类划分

    编号 有效等价类 编号 无效等价类
    1 长度<6 5 长度=0或>7
    2 数字 6 控制字符,标点符号
    3 小写英文字母    
    4 大写英文字母    
    用例编号 一行 二行 三行 结果
    (1)   asd Wer3 非法
    (2) tcy2 Flower lion20 通过
    (3) answ! 21345 3.1415 非法
    (4) 112233 44556 7895999 非法
    (5) apple banana peach 通过
    (6)       非法
    (7) ae34!@ BR_er wer_12 非法
    (8) asdfghjk 123 asnf 非法
    (9) 12345678 fly carer 非法
    (10) Emanon Neo Jhon 通过

    测试结果

    (1)(2)(3)(4)(5) (6)(7)(8)(9)(10)

    import javafx.application.Application;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.TextField;
    import javafx.scene.layout.AnchorPane;
    import javafx.scene.text.Text;
    import javafx.stage.Stage;
    
    
    public class testing extends Application {
    
        public static void main(String[ ] args) {
            testing.launch( args );
        }
        public void start( Stage primaryStage ) {
            primaryStage.setTitle( "input testing" );
            AnchorPane root = new AnchorPane();
            
            Text text = new Text("请输入用户名");
            final Text textans1 = new Text("");
            final Text textans2 = new Text("");
            final Text textans3 = new Text("");
            
            final TextField intext1 = new TextField("");
            intext1.setMaxSize(140, 20);    
            AnchorPane.setTopAnchor(text, 80.0);
            AnchorPane.setLeftAnchor(text, 110.0);       
            
            AnchorPane.setTopAnchor(textans1, 240.0);
            AnchorPane.setLeftAnchor(textans1, 70.0);
            AnchorPane.setTopAnchor(textans2, 260.0);
            AnchorPane.setLeftAnchor(textans2, 70.0);  
            AnchorPane.setTopAnchor(textans3, 280.0);
            AnchorPane.setLeftAnchor(textans3, 70.0);  
            
            AnchorPane.setTopAnchor(intext1, 100.0);
            AnchorPane.setLeftAnchor(intext1, 70.0);        
            
            final TextField intext2 = new TextField("");
            final TextField intext3 = new TextField("");
            intext2.setMaxSize(140, 20); 
            intext3.setMaxSize(140, 20); 
            AnchorPane.setTopAnchor(intext2, 140.0);
            AnchorPane.setLeftAnchor(intext2, 70.0); 
            AnchorPane.setTopAnchor(intext3, 180.0);
            AnchorPane.setLeftAnchor(intext3, 70.0); 
            
            root.getChildren().addAll(text,intext1,intext2,intext3);  
            root.getChildren().addAll(textans1,textans2,textans3);
            
            Button btn = new Button("提交");        
            root.getChildren().addAll(btn);
            AnchorPane.setTopAnchor(btn, 210.0);
            AnchorPane.setLeftAnchor(btn, 120.0);
           
            btn.setOnAction(new EventHandler<ActionEvent>() {
                public void handle(ActionEvent arg0) {
                    textans1.setText("");
                    textans2.setText("");
                    textans3.setText("");             
                    if(check(intext1.getText().toString()) != "输入正确") 
                        textans1.setText("一号未通过:"+check(intext1.getText().toString()));
                    if(check(intext2.getText().toString()) != "输入正确") 
                        textans2.setText("二号未通过:"+check(intext2.getText().toString()));
                    if(check(intext3.getText().toString()) != "输入正确") 
                        textans3.setText("三号未通过:"+check(intext3.getText().toString()));
                    if(check(intext1.getText().toString())== "输入正确" && 
                       check(intext2.getText().toString())== "输入正确"&&
                       check(intext3.getText().toString())== "输入正确")
                    {
                        textans1.setText("通过");
                        textans2.setText("");
                        textans3.setText("");
                    }
                }
            });
          
            primaryStage.setScene(new Scene(root,300,300));
            primaryStage.show( );
            }
            public String check(String str){
                char array[] = new char[str.length()];
                array = str.toCharArray();
                if (str.length() < 1)
                    return "输入不能为空";          
                if (str.length() > 6)
                    return "输入超出长度限制,请修改"; 
                if (str.length() != 0){
                    for (int i = 0; i < str.length(); i++){
                        if(!((array[i]>='a' && array[i]<='z')||(array[i]>='A' && array[i]<='Z')||(array[i]>='0' && array[i]<='9')))
                           return "含有非法字符,请修改";
                    }
                }
                return "输入正确";
          }
     
    }
  • 相关阅读:
    如何解决C#异常:必须先将当前线程设置为单线程单元(STA)模式,然后才能进行OLE调用,请确保你的Main函数已在其上标记了STAThreadAttribute
    go多态
    go泛型
    protoc工具使用
    grpc protobuf协议
    grpc根据proto文件自动生成go源码
    go安装grpc
    go protobuf
    go读取http.Request中body的内容
    go数据库操作
  • 原文地址:https://www.cnblogs.com/voidsh/p/4375957.html
Copyright © 2011-2022 走看看