测试用例程序应用

发表于:2015-3-30 12:51

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:一班&缪为正    来源:51Testing软件测试网采编

  上一篇介绍了测试用例的概念和一些例子,这次就让我们应用一下这些理论吧。
  对于问题:
  允许1到6个英文字符或数字,按OK结束
  有效等价类: 长度:1到6;字符:a-z,A-Z,0-9
  无效等价类:长度:0,7;字符:英文、数字以外字符,控制字符,标点符号等
  要求用三个文本框输入进行测试,代码如下:
1 import java.awt.event.MouseAdapter;
2
3 import javafx.application.Application;
4 import javafx.event.ActionEvent;
5 import javafx.event.EventHandler;
6 import javafx.scene.Scene;
7 import javafx.scene.control.Button;
8 import javafx.scene.control.TextArea;
9 import javafx.scene.input.MouseEvent;
10 import javafx.scene.layout.AnchorPane;
11 import javafx.stage.Stage;
12
13
14 public class testview extends Application{
15     public TextArea text[]=new TextArea[3];
16     /**
17      * @param args
18      */
19     public static void main(String[] args) {
20         // TODO Auto-generated method stub
21         Application.launch(args);
22     }
23     public void start(Stage stage) throws Exception{
24         stage.setTitle("Testing");
25         AnchorPane root=new AnchorPane();
26         Scene scene=new Scene(root,300,300);
27
28         for(int i=0;i<3;i++){
29             text[i]=new TextArea();
30             text[i].setLayoutX(20);
31             text[i].setLayoutY(i*30+100);
32             text[i].setMaxHeight(30);
33             text[i].setPrefColumnCount(10);
34             root.getChildren().add(text[i]);
35         }
36         Button btn=new Button("OK");
37         btn.setLayoutX(100);
38         btn.setLayoutY(200);
39         root.getChildren().add(btn);
40         btn.setOnAction(new EventHandler<ActionEvent>(){
41             public void handle(ActionEvent e){
42                 String str = new String();
43                 boolean result=true;
44                 for(int i=0;i<3;i++){
45                     result=true;
46                     str= text[i].getText();
47                     if(str.length()>0 && str.length()<7){
48                         for(int j=0;j<str.length();j++){
49                             if(!Character.isDigit((str.charAt(j)))&&!Character.isLetter(str.charAt(j))) {
50                                 result=false;
51                                 break;
52                             }
53                         }
54                     }
55                     else result=false;
56                 System.out.println(result);
57                 }
58
59             }
60         });
61         stage.setScene(scene);
62         stage.show();
63     }
64 }
《2023软件测试行业现状调查报告》独家发布~

精彩评论

  • jerrygu625
    2015-4-01 16:17:53

    通过浏览器点刷新

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号