Art of Software Testing (reading notes 2)

The following book is the beginning of the second part of the study notes section

The second part of Software Testing

  It includes case design Chapter 4; Chapter 5 units (modules) tests; Chapter 6 higher level test

Chapter 4 test case design

   Due to time and cost constraints, can design and build a set of test cases can be found in the most error becomes very important.

  This chapter describes common black box and white box approach to design test cases, so that when the actual test, designed to be a comprehensive two methods of use cases. First, a method using a black box test cases, and optionally supplemented with a white box test methods.

  1, black box

  Black box does not meet the aim is to find where the program specification, including the equivalent division method, boundary value method, cause and effect diagram (not used).

  1) equivalence partitioning method

  The program is divided into a limited input range of equivalence classes, the test equivalence class is equivalent to the other test data class. Equivalence partitioning test design method has two steps: (1) determining equivalence classes; (2) to generate test cases;

  (1) determining equivalence classes

    First, select each input condition (a sentence or phrase in a program specification), which is divided into two or more groups (class); then, after dividing each group into equivalence classes and the effective invalidation price category

External input conditions Effective equivalence class Invalid equivalence class
Number may be from 1 to 999 (range) 1 <Number <999 Number <1, ​​Number> 999
Car registered owner (number value) one to six There are 1-6 owners No owner or owners of more than 6

The vehicle must be (a set of input values) buses, trucks, taxis, trains or motorcycle

Enter a vehicle trailer
The first character of the identifier must be a letter (provisions "must be" case) The first character is a letter The first character is not alphabetic

  (2) to generate test cases

    1. Set the number of each equivalence class

    2. write test cases, covered more effectively equivalence classes uncovered

    3. write test cases, covering the uncovered invalid equivalence class

  2) boundary value analysis

  Boundary conditions, refer to the input and output state exactly those equivalence class at the boundary or beyond the boundary, the boundary or less. And wherein no equivalence partitioning

Examples method Data Selector Input / output conditions
Equivalence partitioning Can any one element Focus only on condition input
Boundary value analysis Each boundary element Input and output are concerned

  General guidance on boundary conditions

External conditions Boundary conditions example
Specified range of input values For cross-border cases just design invalid input design use case In the range of -1.0 to +1.0, -1.0, 1.0 should, according to the design -1.001 -1,001 and
A prescribed number of input values For the minimum number, the maximum number is less than a minimum number, one more than the minimum number of case design Input file records can accommodate 1-255, design should be based 0,1,255,256
A predetermined output value range For cross-border cases just use case design invalid output design A program deduction amount ¥ 0.00 to ¥ 1165.25, the design should be deducted in the case of ¥ 0.00 and ¥ 1165.25, while the design results in a negative amount deducted or exceed ¥ 1165.25 use cases
The number of prescribed output value For the minimum number, the maximum number is less than a minimum number, one more than the minimum number of case design The information retrieval system to retrieve the required number of not more than four records, should be designed to show the number of 0, 1 and 4 record, also designed for display of Example 5
O is an ordered sequence (sequential file, linear list) The first and last element of the sequence

  3) The method of FIG causal

  Boundary value analysis and equivalence partitioning does not have to analyze the input combination of conditions, and may cause FIG. FIG causal object is selected with a high collection system test method. Some commercial software can help, you can understand when used.

  2, white-box testing

   White-box testing focuses on the source code of the program logic and structure is executed successfully. Including, statement coverage, decision coverage, condition coverage determination / condition coverage, multiple condition coverage.

  1) Statement Coverage

  Definition: the program each statement is executed at least once.  

public void foo(int a, int b, int x) {
    if (A>1 && B==0) {
        X = X/A;
    }
    if (A==2 || X>1) {
        X=X+1;
    }
}

   如果A=2,B=0,X=3,每条语句被执行一次,但并没有发现什么错误,没有什么用处。

  2)判定覆盖或分支覆盖

  定义:编写足够测试用例,使得每一个判断都至少有一个为真和为假的输出结果。

public void foo(int a, int b, int x) {
    if (A>1 && B==0) {
        X = X/A;
    }
    if (A==2 || X>1) {
        X=X+1;
    }
}

  如下图所示,如果按照判定覆盖定义去设计测试用例,只需要设计测试用例,涵盖路径ace和abd,或者涵盖路径acd和abe就可以满足要求。如果选择acd和abe路径,测试用例的输入A=3,B=0,X=3和A=2,B=1,X=1。如果第二个判断存在错误,测试用例是无法发现错误。

       

  3)条件覆盖

  定义:编写足够的测试用例,将一个判断中的每个条件的所有可能结果至少执行一次。条件覆盖比判定强,因为条件覆盖会使判断中每个条件都取两个结果(真和假)。

  比如在a点处有两个条件A>1和B=0,那么需要设计测试用例,能在a点处出现A>1,A<=1,B=0和B<>0的情况。

  虽然条件覆盖能够满足判断中条件的真假,但是对判断语句的真假不能满足。所以需要将判定覆盖和条件覆盖进行结合。

  4)判定/条件覆盖

  定义:设计足够的测试用例,将判断中每个条件的所有可能的结果至少执行一次,且将每个判断的所有可能的结果至少执行一次。

  如下图所示将判定和条件覆盖进行结合,但是因为A>1和B=0是相“与”的关系,A=2和X>1是相“或”的关系,在编译器中,如果“与”表达式中有个条件为“假”,则不会执行后续条件;如果“或”表达式中有个条件为“真”,不会执行后续条件。程序不能执行H中为假的分支,以及判断K中为真的分支。所以判定/条件覆盖可能不会发现逻辑表达式中的错误。 

 
  5)多重条件覆盖
  定义:编写足够多测试用例,将每个判定中的所有可能的条件结果的组合,以及所有的入口点都至少执行一次。存在循环情况下,多重条件覆盖准则所需测试用例数量远小于其路径数量。
    if(x==y && length(z)==0 && FLAG) {
        j = 1;
    }
    else {
        i = 1;
    }

  对以上判定语句进行分析,每个条件有以下三种情况

    1.x==y,x!=y

    2.length(z) ==0,length(z)<>0

    3.FLAG,!FLAG

  从三种情况进行条件组合,有8个测试用例

    1.x==y,length(z) ==0,FLAG

    2.x==y,length(z) ==0,!FLAG

    3.x==y,length(z)<>0,FLAG

    4.x==y,length(z)<>0,!FLAG

    5.x!=y,length(z) ==0,FLAG

    6.x!=y,length(z) ==0,!FLAG

    7.x!=y,length(z)<>0,FLAG

    8.x!=y,length(z)<>0,!FLAG

  3、错误猜测方法

  是一种依赖直觉的非正规过程。基本思想是列举出可能犯的错误或错误易发情况的清单,然后根据清单来编写测试用例。这种方法很难系统化,严重依赖于个人能力。

  假设测试一个排序程序,应探讨如下情况测试用例

  1.输入列表为空

  2.输入列表仅包含一个条目

  3.输入列表所有条目的值都相等

  4.输入列表已经排过序

  综上,测试用例的设计,首先,可以根据规格说明书文档,通过黑盒方法中的有效等价类和边界值分析方法进行设计;然后,根据测试经验用错误猜测方法增加更多的测试用例;最后,可以检查程序的逻辑结构,使用判定覆盖、条件覆盖、判定/条件覆盖或多重条件覆盖准则进行用例设计。

 

Guess you like

Origin www.cnblogs.com/chengabc/p/11254877.html