Implementation of the EditBox problem and a brief description of the JUnit test framework

Source: Internet
Author: User

First, this week's editbox from a box to three boxes, while testing, the following shows the program and

 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 public class Test1 extends application {All public static boo  Lean Isregularrptcode (String rptcode,string regex) {Pattern P1 = pattern.compile (regex); Matcher m1 = P1.matcher (Rptcode), Boolean rs1 = M1.matches (), return rs1;21}22 public static void main (St Ring[] (args) {test1.launch (args),}25 public void start (stage stage) throws Exception {Stag E.settitle ("UserForm1"), Anchorpane root = new Anchorpane (), and scene scene = new Scene (Root, Scene.setfill (color.pink), + text name= new text ("Name1"), Name.setfont (Font.         Font ("Stxingkai"), Anchorpane.settopanchor (name, 25.0), Anchorpane.setleftanchor (name, 50.0); 34 Text name1= new text ("Name2"), Name1.setfont (Font.font ("Stxingkai"), Anchorpane.settopan Chor (name1, 75.0), PNs Anchorpane.setleftanchor (name1, 50.0), + text name2= new text ("Name3"); E2.setfont (Font.font ("Stxingkai"), Name2 Anchorpane.settopanchor (125.0, anchorpane.setleftanch); or (name2, 50.0); final TextField tf=new TextField (); Anchorpane.settopanchor (TF, 34.0); anch Orpane.setleftanchor (TF, 145.0); final TextField tf1=new TextField (); Anchorpane.settopanchor (TF1, 84. 0); Anchorpane.setleftanchor (TF1, 145.0); final TextField tf2=new TextField (); anchorpane.se Ttopanchor (TF2, 134.0); 50 Anchorpane.setleftanchor (TF2, 145.0); button button = New button ("OK"); Anchorpane.settopanc Hor (button, 134.0); Anchorpane.setleftanchor (button, 350.0); Button.setonaction (New Eventhandler<a Ctionevent> () {handle (ActionEvent actevt) {$ final String name_ = Tf.gettext (); final string name_1 = Tf1.gettext (); the final string name_2 = Tf2.gettext () ; if (name_.length () <1| |  Name_.length () >6) {System.out.println ("name1 length should be 1-6");}62 Else                 if (!isregularrptcode (name_, "[a-z,a-z,0-9]*")) {System.out.println ("name1 character should be 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) {System.out.println ("name2 lengthshould be 1-6 "),}71 else if (!isregularrptcode (Name_1," [a-z,a-z,0-9]* ")) {72 System.out.println ("name2 character should be a-z,a-z,0-9");}74 else{75 SYSTEM.OUT.P Rintln ("Name2ok");}77 if (Name_2.length () <1| | Name_2.length () >6) {System.out.println ("Name3 length shall be 1-6");}80 Els                 E if (!isregularrptcode (name_2, "[a-z,a-z,0-9]*")) {Bayi System.out.println ("Name3 character should be a-z,a-z,0-9"); 82                }83 else{84 System.out.println ("Name3ok"); 85} }87}); Root.getchildren (). AddAll (Name,name1,name2,tf,tf1,tf2,button); Ge.setscene (scene); Stage.show (); 91}92}

Here are a few test cases:

Name1 Name2 Name3 Console returns results
Fdf Rrea S1a2
FADFD, Gfdgfd21 da1.,
Hdgg 3242435 Null
,. Eda E2t2 Fa1sfs3

Ii. a brief description of JUnit below

JUnit is an open-source Java test Framework for writing and running repeatable tests. He is an example for the xunit of the Unit Test framework system (for the Java language). It includes the following features:

1. Assertions for testing desired results (assertion)

2. Test tools for sharing common test data

3. Test suite for convenient organization and run test

4. Test runner for graphics and text

I downloaded JUnit's source code from the Internet and used Sonarqube to analyze it for analysis of the results:

Implementation of the EditBox problem and a brief description of the JUnit test framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.