• 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的测试截图:

  • 相关阅读:
    [Hadoop 周边] Hadoop和大数据:60款顶级大数据开源工具(2015-10-27)【转】
    [Nginx] 关键概念解读
    [随想感悟] 研究技术的方法
    [Hadoop 周边] 浅谈大数据(hadoop)和移动开发(Android、IOS)开发前景【转】
    [优化] 数据库优化基础
    [随想感悟] 面试时,问哪些问题能试出一个 Android 应用开发者真正的水平?【转自知乎】
    258. Add Digits
    257. Binary Tree Paths
    256. Paint House
    255. Verify Preorder Sequence in Binary Search Tree
  • 原文地址:https://www.cnblogs.com/CrystalN/p/4375649.html
Copyright © 2020-2023  润新知