Last week's test involved an input box, and the test will test 3 input boxes at the same time.
Improved the last code by adding 3 boxes
The user name, password and verification code are respectively.
The password and user name require a number or letter of length 0-6
The verification code is a 4-digit number and needs to be entered with the same number as the verification code before it is determined to be correct.
To design a test case:
Input expected output actual output
123aa
123 Legal legality
Legal Verification Code
123aa.
123 Illegal or illegal
Legal Verification Code
123aa
123.
Legal verification code is illegal and illegal
123aa
123
Illegal verification code is not legal illegal
Here is the test:
Main code:
Anchorpane root = new Anchorpane ();
Final String str1 = "valid";
Final String str2 = "illegal";
User name
Final TextField textfiled1 = new TextField ();
Root.getchildren (). AddAll (textfiled1);
Anchorpane.settopanchor (textfiled1,100.0);
Anchorpane.setleftanchor (textfiled1,100.0);
Text Text1 = new text ();
Text1.settext ("User name");
Root.getchildren (). AddAll (Text1);
Anchorpane.settopanchor (text1,100.0);
Anchorpane.setleftanchor (text1,50.0);
Password
Final TextField textfiled2 = new TextField ();
Root.getchildren (). AddAll (TEXTFILED2);
Anchorpane.settopanchor (textfiled2,150.0);
Anchorpane.setleftanchor (textfiled2,100.0);
Text Text2 = new text ();
Text2.settext ("password");
Root.getchildren (). AddAll (Text2);
Anchorpane.settopanchor (text2,150.0);
Anchorpane.setleftanchor (text2,50.0);
Verification Code
Final TextField textfiled3 = new TextField ();
Root.getchildren (). AddAll (TEXTFILED3);
Anchorpane.settopanchor (textfiled3,200.0);
Anchorpane.setleftanchor (textfiled3,100.0);
Text Text3 = new text ();
Text3.settext ("Verification Code");
Root.getchildren (). AddAll (TEXT3);
Anchorpane.settopanchor (text3,200.0);
Anchorpane.setleftanchor (text3,50.0);
Final text Text4 = new text ();
Root.getchildren (). AddAll (TEXT4);
Anchorpane.settopanchor (text4,200.0);
Anchorpane.setleftanchor (text4,300.0);
Random ran = new random ();
final int a = Ran.nextint (9000) +1000;
Text4.settext (A + "");
Final text text = new text ();
Root.getchildren (). AddAll (text);
Anchorpane.settopanchor (text,100.0);
Anchorpane.setleftanchor (text,300.0);
Button btn = New button ("OK");
Root.getchildren (). AddAll (BTN);
Anchorpane.settopanchor (btn,250.0);
Anchorpane.setleftanchor (btn,100.0);
btn.setonmouseclicked (New eventhandler<mouseevent> () {
public void handle (MouseEvent arg0) {
Boolean judge1 = true;
Boolean judge2 = true;
String s = textfiled1.gettext ();
if ((S.length () > 6) | | (S.length () < 1))
{
Text.settext (STR2);
Return
}
for (int i = 0; i < s.length (); i++)
{
char C = S.charat (i);
if (! ( (c >= ' A ' && C <= ' Z ') | | (c >= ' a ' && c <= ' z ') | | (c >= ' 0 ' && C <= ' 9 ')))
{
Judge1 = false;
Break
}
}
if (!judge1)
{
Text.settext (STR2);
Return
}
s = Textfiled2.gettext ();
if ((S.length () > 6) | | (S.length () < 1))
{
Text.settext (STR2);
Return
}
for (int i = 0; i < s.length (); i++)
{
char C = S.charat (i);
if (! ( (c >= ' A ' && C <= ' Z ') | | (c >= ' a ' && c <= ' z ') | | (c >= ' 0 ' && C <= ' 9 ')))
{
Judge2 = false;
Break
}
}
if (!judge2)
{
Text.settext (STR2);
Return
}
s = Textfiled3.gettext ();
int I=integer.parseint (s);
if (i! = a)
{
Text.settext (STR2);
}
Else
{
Text.settext (STR1);
}
}
});
Stage.setscene (new Scene (root, 500, 500));
Stage.show ();
Black box Test Cont.