zoukankan      html  css  js  c++  java
  • Java上等价类划分测试的实现

    利用JavaFx实现对有效等价类和无效等价类的划分:

    代码:

    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.Label;
    import javafx.scene.control.TextField;
    import javafx.scene.layout.AnchorPane;
    import javafx.scene.text.Font;
    import javafx.scene.text.FontWeight;
    import javafx.scene.text.Text;
    import javafx.stage.Stage;


    public class Main extends Application{
    TextField textField;
    Label label;

    public static void main(String[] args) {
    Application.launch(args);
    }

    public void start(Stage stage){
    stage.setTitle("For Test");
    AnchorPane root = new AnchorPane();
    Scene scene = new Scene(root, 500, 300);

    Text text = new Text();
    text.setText("Write something for test:");
    text.setFont(Font.font("Comic Sans MS", 18));
    AnchorPane.setTopAnchor(text, 0.0);
    AnchorPane.setLeftAnchor(text, 10.0);

    Text text2 = new Text();
    text2.setText("Result:");
    text2.setFont(Font.font("Comic Sans MS", 18));
    AnchorPane.setTopAnchor(text2, 50.0);
    AnchorPane.setLeftAnchor(text2, 10.0);

    label = new Label(" ");
    label.setFont(Font.font ("Comic Sans MS", 16));
    AnchorPane.setTopAnchor(label, 90.0);
    AnchorPane.setLeftAnchor(label, 50.0);

    Button button = new Button();
    button.setText(" Sure ");
    AnchorPane.setTopAnchor(button, 5.0);
    AnchorPane.setLeftAnchor(button, 420.0);

    textField = new TextField ();
    textField.setPrefWidth(160);
    textField.getText();
    AnchorPane.setTopAnchor(textField, 5.0);
    AnchorPane.setLeftAnchor(textField, 250.0);

    button.setOnAction(new EventHandler<ActionEvent>() {

    @Override
    public void handle(ActionEvent e) {
    char input[] = textField.getText().toCharArray();
    int errorcase = 3;
    if (textField.getText().length()==0 || textField.getText().length() >= 7) {
    errorcase = 1;
    }
    else {
    for(int i=0;i<textField.getText().length();i++){
    if(!((input[i]>=48 && input[i]<57) || (input[i]>=65 && input[i]<=90) || (input[i]>=97 && input[i]<=122))){
    errorcase = 2;
    break;
    }
    }
    }
    switch(errorcase){

    case 1:
    label.setText("Input is " + textField.getText() + " " + "Error1: The length of input is error");
    break;

    case 2:
    label.setText("Input is " + textField.getText() + " " + "Error2: The kind of input is error");
    break;

    case 3:
    label.setText("Input is " + textField.getText() + " " + "Succeed: Input is correct");

    }
    }
    });

    root.getChildren().addAll(text,text2,textField,button,label);
    stage.setResizable(false);
    stage.setScene(scene);
    stage.show();
    }
    }

    等价类划分和测试用例设计:


    编号1、2、3、8、11、17的测试截图:

  • 相关阅读:
    四人过桥求最短时间(《算法设计与分析》习题一的第8题) Apare_xzc
    已知中序后序遍历还原二叉树(uva 548) Apare_xzc
    大二下学期第四周周报(2019.3.24) Apare_xzc
    大二下学期第五周周报(2019.3.31) Apare_xzc
    拓扑排序复习(处女座的比赛资格)
    exgcd复习 Apare_xzc
    ACM课程设计课 Advance_Contest_1 解题报告 Apare_xzc
    使用共享内存
    使用信号量
    使用命名管道
  • 原文地址:https://www.cnblogs.com/CrystalN/p/4375649.html
Copyright © 2011-2022 走看看