黑盒测试续

上周的测试涉及到一个输入框,本次测试将对3个输入框同时进行测试。

对上次的代码进行改进,增加3个框

分别是用户名,密码和验证码。

密码和用户名一样,要求为长度0-6的数字或字母

验证码为4位数字,需要输入与验证码相同的数字才判定为正确。

设计测试用例:

输入                 预期输出               实际输出

123aa

123                 合法                     合法

合法验证码

123aa.

123                 不合法                 不合法

合法验证码

123aa

123.

合法验证码        不合法                 不合法

123aa

123

不合法验证码     不合法                 不合法

下面为测试截图:

主要代码:

AnchorPane root = new AnchorPane();

final String str1 = "合法";
final String str2 = "不合法";
//用户名
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("用户名");
root.getChildren().addAll(text1);
AnchorPane.setTopAnchor(text1,100.0);
AnchorPane.setLeftAnchor(text1,50.0);

//密码
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("密码");
root.getChildren().addAll(text2);
AnchorPane.setTopAnchor(text2,150.0);
AnchorPane.setLeftAnchor(text2,50.0);

//验证码
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("验证码");
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("确定");
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( );

原文地址:https://www.cnblogs.com/lushengli1234/p/4375818.html