标签:
一、这周的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 }
以下为几个测试用例:
name1 | name2 | name3 | 控制台返回结果 |
fdf | rrea | S1a2 | |
fadfd、 | gfdgfd21 | da1.、 | |
hdgg | 3242435 | null | |
,.eda | E2T2 | fa1SFS3 |
二、下面为Junit的简要说明
JUnit是一个开放源代码的Java测试框架,用于编写和运行可重复的测试。他是用于单元测试框架体系xUnit的一个实例(用于java语言)。它包括以下特性:
1、用于测试期望结果的断言(Assertion)
2、用于共享共同测试数据的测试工具
3、用于方便的组织和运行测试的测试套件
4、图形和文本的测试运行器
我从网上下载了Junit的源码并用SonarQube对其进行了代码质量分析,下图为分析结果:
标签:
原文地址:http://www.cnblogs.com/yueyingky/p/4375762.html