您的位置:软件测试 > 开源软件测试 > 开源单元测试工具 > junit
Editbox问题的实现以及Junit测试框架的简要说明
作者:网络转载 发布时间:[ 2015/6/15 13:59:34 ] 推荐标签:单元测试工具

  一、这周的EditBox由一个框改为三个框,同时进行测试,下面给出程序及截图
1 import java.util.regex.Matcher;
2 import java.util.regex.Pattern;
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.TextField;
9 import javafx.scene.layout.AnchorPane;
10 import javafx.scene.paint.Color;
11 import javafx.scene.text.Font;
12 import javafx.scene.text.Text;
13 import javafx.stage.Stage;
14
15 public class Test1 extends Application {
16     public static boolean isRegularRptCode(String rptCode,String regEx) {
17         Pattern p1 = Pattern.compile(regEx);
18         Matcher m1 = p1.matcher(rptCode);
19         boolean rs1 = m1.matches();
20         return rs1;
21     }
22     public static void main(String[] args) {
23         Test1.launch(args);
24     }
25     public void start(Stage stage)throws Exception {
26         stage.setTitle("UserForm1");
27         AnchorPane root = new AnchorPane();
28         Scene scene = new Scene(root, 450, 200);
29         scene.setFill(Color.PINK);
30         Text name= new Text("name1");
31         name.setFont(Font.font ("STXingKai", 36));
32         AnchorPane.setTopAnchor(name, 25.0);
33         AnchorPane.setLeftAnchor(name, 50.0);
34         Text name1= new Text("name2");
35         name1.setFont(Font.font ("STXingKai", 36));
36         AnchorPane.setTopAnchor(name1, 75.0);
37         AnchorPane.setLeftAnchor(name1, 50.0);
38         Text name2= new Text("name3");
39         name2.setFont(Font.font ("STXingKai", 36));
40         AnchorPane.setTopAnchor(name2, 125.0);
41         AnchorPane.setLeftAnchor(name2, 50.0);
42         final TextField tf=new TextField();
43         AnchorPane.setTopAnchor(tf, 34.0);
44         AnchorPane.setLeftAnchor(tf, 145.0);
45         final TextField tf1=new TextField();
46         AnchorPane.setTopAnchor(tf1, 84.0);
47         AnchorPane.setLeftAnchor(tf1, 145.0);
48         final TextField tf2=new TextField();
49         AnchorPane.setTopAnchor(tf2, 134.0);
50         AnchorPane.setLeftAnchor(tf2, 145.0);
51         Button button = new Button("OK");
52         AnchorPane.setTopAnchor(button, 134.0);
53         AnchorPane.setLeftAnchor(button, 350.0);
54         button.setOnAction( new EventHandler<ActionEvent>( ) {
55             public void handle(ActionEvent actEvt) {
56                 final String name_ = tf.getText();
57                 final String name_1 = tf1.getText();
58                 final String name_2 = tf2.getText();
59                 if(name_.length()<1||name_.length()>6){
60                     System.out.println("name1长度应为1-6");
61                 }
62                 else if(!isRegularRptCode(name_,"[a-z,A-Z,0-9]*")){
63                     System.out.println("name1字符应为a-z,A-Z,0-9");
64                 }
65                 else{
66                     System.out.println("name1OK");
67                 }
68                 if(name_1.length()<1||name_1.length()>6){
69                     System.out.println("name2长度应为1-6");
70                 }
71                 else if(!isRegularRptCode(name_1,"[a-z,A-Z,0-9]*")){
72                     System.out.println("name2字符应为a-z,A-Z,0-9");
73                 }
74                 else{
75                     System.out.println("name2OK");
76                 }
77                 if(name_2.length()<1||name_2.length()>6){
78                     System.out.println("name3长度应为1-6");
79                 }
80                 else if(!isRegularRptCode(name_2,"[a-z,A-Z,0-9]*")){
81                     System.out.println("name3字符应为a-z,A-Z,0-9");
82                 }
83                 else{
84                     System.out.println("name3OK");
85                 }
86             }
87         } );
88         root.getChildren().addAll(name,name1,name2,tf,tf1,tf2,button);
89         stage.setScene(scene);
90         stage.show();
91     }
92 }

上一页12下一页
软件测试工具 | 联系我们 | 投诉建议 | 诚聘英才 | 申请使用列表 | 网站地图
沪ICP备07036474 2003-2017 版权所有 上海泽众软件科技有限公司 Shanghai ZeZhong Software Co.,Ltd