zoukankan      html  css  js  c++  java
  • 黑盒测试续

    上周的测试涉及到一个输入框,本次测试将对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( );

  • 相关阅读:
    iOS电商类App研发学习总结
    Swift4.0复习闭包
    Swift4.0复习函数
    Swift4.0复习Optional
    SQL面试题
    sql(join on 和where的执行顺序)
    算法四:回溯和分支界定
    算法三:贪婪算法
    编程之美2.11:寻找最近的点对
    编程之美2.5:寻找最大的K个数
  • 原文地址:https://www.cnblogs.com/lushengli1234/p/4375818.html
Copyright © 2011-2022 走看看