黑盒测试的等价类划分法软件测试(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 "输入正确";
      }
 
}

 

posted on 2015-03-29 17:34  四班&田晨阳  阅读(355)  评论(0编辑  收藏  举报

导航