您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > junit
Editbox問題的實現(xiàn)以及Junit測試框架的簡要說明
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時間:[ 2015/6/15 13:59:34 ] 推薦標(biāo)簽:單元測試工具

  一、這周的EditBox由一個框改為三個框,同時進(jìn)行測試,下面給出程序及截圖
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長度應(yīng)為1-6");
61                 }
62                 else if(!isRegularRptCode(name_,"[a-z,A-Z,0-9]*")){
63                     System.out.println("name1字符應(yīng)為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長度應(yīng)為1-6");
70                 }
71                 else if(!isRegularRptCode(name_1,"[a-z,A-Z,0-9]*")){
72                     System.out.println("name2字符應(yīng)為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長度應(yīng)為1-6");
79                 }
80                 else if(!isRegularRptCode(name_2,"[a-z,A-Z,0-9]*")){
81                     System.out.println("name3字符應(yīng)為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下一頁
軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd