This assignment, I use JavaFX to write a program to test the legitimacy of the input
This is my input interface,
Three boxes input simultaneously,
You can test the legality of three inputs by pressing submit,
Finally display the test results in the console
Test Case:
Division of Equivalence classes:
Valid equivalence classes: Length 1-6, only characters with a-z,a-z,0-9
Invalid equivalence class: length 0 or greater than 7, contains but not necessarily all except a-z,a-z,0-9 characters, control characters, punctuation, and so on.
Here are the test cases
First Test:
Input: er43t
Dgddsgdfg
fds!#
Output:
Ok
All input lengths should be 1-6
All input characters should be a-z,a-z,0-9
:
2nd time Test:
Input: null
4234
#$$%%
Output:
All input lengths should be 1-6
Ok
All input characters should be a-z,a-z,0-9
:
3rd Time Test:
Input: 24324243
ADFs
Space
Output:
All input lengths should be 1-6
Ok
All input characters should be a-z,a-z,0-9
:
The code is as follows:
Package softwtest;
Import Java.util.regex.Matcher;
Import Java.util.regex.Pattern;
Import javafx.application.Application;
Import javafx.event.ActionEvent;
Import Javafx.event.EventHandler;
Import Javafx.scene.Scene;
Import Javafx.scene.control.Button;
Import Javafx.scene.control.TextField;
Import Javafx.scene.layout.AnchorPane;
Import Javafx.scene.text.Text;
Import Javafx.stage.Stage;
public class Test extends application{
public static Boolean Isregularrptcode (String rptcode,string regEx) {
Pattern P1 = Pattern.compile (regEx);
Matcher m1 = P1.matcher (Rptcode);
Boolean rs1 = M1.matches ();
return rs1;
}
public static void Main (string[] args) {
Test.launch (args);
}
public void start (stage stage) {
Stage.settitle ("test");
Anchorpane root = new Anchorpane ();
Stage.setscene (new Scene (root, 500, 250));
Text name1= new text ("name");
Text name2= new text ("Password");
Text name3= new Text ("Verification Code");
Final TextField []TF = new textfield[3];
Tf[0] = new TextField ();
TF[1] = new TextField ();
TF[2] = new TextField ();
Button btn = New button ();
Btn.settext ("submit");
Anchorpane.settopanchor (name1, 50.0);
Anchorpane.setleftanchor (name1, 50.0);
Anchorpane.settopanchor (name2, 100.0);
Anchorpane.setleftanchor (name2, 50.0);
Anchorpane.settopanchor (Name3, 150.0);
Anchorpane.setleftanchor (Name3, 50.0);
Anchorpane.settopanchor (Tf[0], 50.0);
Anchorpane.setleftanchor (Tf[0], 105.0);
Anchorpane.settopanchor (tf[1], 100.0);
Anchorpane.setleftanchor (tf[1], 105.0);
Anchorpane.settopanchor (tf[2], 150.0);
Anchorpane.setleftanchor (tf[2], 105.0);
Anchorpane.settopanchor (BTN, 200.0);
Anchorpane.setleftanchor (BTN, 210.0);
Btn.setonaction (New eventhandler<actionevent> () {
public void handle (ActionEvent actevt) {
Final String []namex = new string[3];
for (int i=0;i<3;i++) {
Namex[i] = Tf[i].gettext ();
if (Namex[i].length () <1| | Namex[i].length () >6) {
SYSTEM.OUT.PRINTLN ("All input lengths should be 1-6");
}
else if (!isregularrptcode (Namex[i], "[a-z,a-z,0-9]*")) {
SYSTEM.OUT.PRINTLN ("All input characters should be a-z,a-z,0-9");
}
else{
System.out.println ("OK");
}
}
}
} );
Root.getchildren (). Add (BTN);
Root.getchildren (). Add (name1);
Root.getchildren (). Add (name2);
Root.getchildren (). Add (Name3);
Root.getchildren (). Add (Tf[0]);
Root.getchildren (). Add (Tf[1]);
Root.getchildren (). Add (tf[2]);
Stage.show ();
}
}
Software testing third week job--testing the legitimacy of multiple inputs