zoukankan      html  css  js  c++  java
  • 软件测试之等价类的划分及应用

    所谓等价类是指输入域的某个互不相交的子集合,所有等价类的并集便是整个输入域。目的在于测试用例的无冗余性。

    有效等价类:检验程序是否实现了规格说明预先规定的功能和性能。

    无效等价类:检查软件功能和性能的实现是否有不符合规格说明要求的地方。

    一、等价类的划分方法:

    (1)按区间划分:可以确定一个有效等价类、两个无效等价类。

    (2)按数值划分:如果输入条件规定了输入数据的一组可能的值,而且程序是用不同的方式处理每一种值,则可为每一种值划分一个有效等价类,并划分一个无效等价类。

    (3)按数值集合划分:规格说明中规定了输入值的集合,则可以确定一个有效等价类,并划分一个无效等价类。

    (4)按限制条件或规则划分:规格说明中规定了输入数据必须遵守的规则和限制条件,则可以确立一个有效等价类(符合规则)和若干个(≥ 1)无效等价类(不同角度的违反规则)。

    (5)细分等价类:如果我们确知,已划分的某等价类中的各元素(例子)在程序中的处理方式是不同的,则应据此将此等价类进一步划分成更小的等价类。

     
     
    二、等价类测试用例设计

    (1)在确立了等价类之后,可列出所有划分出的等价类表。

    (2)为每一个等价类规定一个唯一的编号。

    (3)设计一个新的测试用例,使其尽可能多地覆盖尚未覆盖的有效等价类。重复这一步,直到测试用例覆盖了所有的有效等价类。

    (4)设计一个新的测试用例,使其覆盖且只覆盖一个尚未覆盖的无效等价类。重复这一步,直到测试用例覆盖了所有的无效等价类。

    三、针对EditBox问题给出答案

    以输入条件划分等价类:

    有效等价类 无效等价类

    E1:长度为1到6

    T1:长度为0
    T2:长度大于6
    E2:字符为a-z,A-Z,0-9 T3:字符为字母和数字以外字符

    给出程序及截图:

    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    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.TextField;
    import javafx.scene.layout.AnchorPane;
    import javafx.scene.paint.Color;
    import javafx.scene.text.Font;
    import javafx.scene.text.Text;
    import javafx.stage.Stage;
    
    public class Test1 extends Application {
        public static boolean isRegularRptCode(String rptCode,String regEx) {
            Pattern p1 = Pattern.compile(regEx);
            Matcher m1 = p1.matcher(rptCode);
            boolean rs1 = m1.matches();
            return rs1;
        }
        public static void main(String[] args) {
            Test1.launch(args);
        }
        public void start(Stage stage)throws Exception {
            stage.setTitle("UserForm1");
            AnchorPane root = new AnchorPane();
            Scene scene = new Scene(root, 500, 150);
            scene.setFill(Color.PINK);
            Text name= new Text("姓名");
            name.setFont(Font.font ("STXingKai", 36));
            AnchorPane.setTopAnchor(name, 50.0);
            AnchorPane.setLeftAnchor(name, 50.0);
            final TextField tf=new TextField();
            AnchorPane.setTopAnchor(tf, 57.0);
            AnchorPane.setLeftAnchor(tf, 145.0);
            Button button = new Button("OK");
            AnchorPane.setTopAnchor(button, 57.0);
            AnchorPane.setLeftAnchor(button, 350.0);
            button.setOnAction( new EventHandler<ActionEvent>( ) {
                public void handle(ActionEvent actEvt) {        
                    final String name1;
                    name1=tf.getText();
                    if(name1.length()<1||name1.length()>6){
                        System.out.println("长度应为1-6");
                    }
                    else if(!isRegularRptCode(name1,"[a-z,A-Z,0-9]*")){
                        System.out.println("字符应为a-z,A-Z,0-9");
                    }
                    else{
                        System.out.println("OK");
                    }
                }
            } );
            root.getChildren().addAll(name,tf,button);
            stage.setScene(scene);
            stage.show();
        }
    }

    以下为几个测试用例:

    编号 输入 控制台返回结果
    E1,E2 S1a2
    E1,T3 da1.、
    E2,T1 null
    E2,T2 fa1SFS3
  • 相关阅读:
    加分二叉树
    香甜的黄油 Sweet Butter
    09.22今日暂时停更题解
    能量项链
    转圈游戏
    字串变换
    关押罪犯
    选择客栈
    神经网络
    未整理算法的总结
  • 原文地址:https://www.cnblogs.com/yueyingky/p/4357729.html
Copyright © 2011-2022 走看看