Software Testing - White Box Testing: Logic Coverage

logic coverage

References:
Software Testing Chapter 4 White Box Testing
- Software Testing - White Box Testing
White Box Testing - Coverage Testing (Six Coverage Methods)

Several common logic coverage testing methods

Purpose: Structural testing is a test that designs test cases based on the logical structure of the program under test and drives the program under test to run and complete. Logical coverage can give coverage criteria for structural tests, ie conditions under which testing can be terminated.
logic coverage examples

  • Statement coverage
    First design several test cases, so that each executable statement in the program is executed at least once. The so-called "several" here is naturally the less the better.
    Case1: A=2, B=0, X=3. The statement coverage can be achieved, and the path is ace.
    Why did you reach it? Didn't b and d not leave? Think again, are there any sentences on b and d? (Go through the line with the statement in the figure)
    If the AND of the first judgment is written as OR, or the second OR is written as AND, the first parameter case is still used, and the statement coverage is still achieved, but no error can be found.
  • Decision coverage (branch) Design several test cases, so that the true and false branches
    of each judgment in the program are experienced at least once, that is, the true and false values ​​of the judgment have been satisfied. Case2: A=1, B=0, X=1, the path is abd. Case1 and Case2 together can achieve decision coverage. However, the second judgment X>1 is wrongly written as X<1, and the error cannot be found. What is judgment? The if statement in the rhombus is the judgment statement. For example, in this question, there are 2 judgments. When both judgments have been executed T and F (4 cases), the judgment coverage is completed.

  • Condition coverage
    Design several test cases so that the possible values ​​of each condition in each judgment are satisfied at least once.
    Case3: A=2, B=1, X=1, the path is abe. Case1, Case2 and Case3 together can achieve condition coverage.
    What are conditions? Split by logical operators, each result is a condition. For example, in this question, there are 4 conditions. When T and F have been executed for all 4 conditions, the condition coverage is completed.
    condition coverage
  • Decision-Condition Coverage
    Design sufficient test cases so that all possibilities of each condition in the judgment appear at least once, and the judgment result of each judgment itself also appears at least once.
    Case1, Case2 and Case3 together can realize decision-condition coverage.
    Why? Because every line is covered, all conditions are also covered. (Here is different from some PPTs because they do not consider conditional combination coverage)
  • Condition combination coverage
    Design enough test cases so that all the possibilities of each condition in the judgment appear at least once, and the judgment result of each judgment itself also appears at least once. The difference between it and condition coverage is that it does not simply require each condition to have both "true" and "false" results, but allows all possible combinations of these results to appear once.
    Condition combination coverage
    The combination of conditions is only for the case where there are multiple conditions in the same judgment statement. Let these added values ​​be combined in a Cartesian product.
  • Path coverage
    Design enough test cases to cover all possible paths in the program.
    Case3: A=3, B=0, X=1, the path is acd. Case1, Case2, Case3, and Case4 together can implement path coverage.
    Condition combination coverage

Calculation of minimum number of test cases

The structured program is composed of three basic control structures: sequential, selective, and repetitive. In order to simplify the problem and avoid combinatorial explosion with too many test cases, the repetitive structure that constitutes the loop operation is replaced by a selection structure.
The basic control structure represented by NS diagram
How to calculate the minimum number of test cases? Let's look at a simple question first.
The basic control structure represented by NS diagram
Provide at least 4 test cases to achieve logic coverage. The 4 here is obtained by combining the two operations induced by the first branch predicate in the figure and the two operations induced by the second branch predicate in the figure, that is, 2 × 2 = 4, and the 2 here is obtained due to the two parallel operations 1 + 1 = 2.
Summary: add in parallel, multiply in series.
The basic control structure represented by NS diagram
Calculation formula: (5*3+1)*3=48
Steps: ((5,4,3,2)(7,6),(1))(9,8)
Core: peel off layer by layer. Continue to divide the series and parallel connections until there are only Y and N, and then start the reverse calculation.

The starting point of logic coverage is reasonable and complete. The so-called "coverage" means to be comprehensive and without omission, but the logic coverage cannot really be without omission. If (x>
3&&z<10) is accidentally written as if(x>=3&&z<10), according to the previously designed test case (x takes 2 or 4), the logic coverage is powerless to such a problem, and the reason is that the error area is only at the point of x=3, that is, only when the value of x is 3, the test can find the error. And here it is used Two guidelines that need to be followed in test coverage: ESTCA guidelines, LCSAJ guidelines. FOSTER's ESTCA coverage guidelines
:

  • For branch predicates of type A rel B (rel can be <, = and >), the values ​​of A and B should be selected appropriately so that when the test executes to the branch statement, the cases of A<B, A = B and A>B occur once respectively.
  • For a branch predicate of type A rel1 C (rel1 can be < or >, A is a variable, and C is a constant), when rel1 is <, the value of A should be properly selected so that A = C − M; when rel1 is >, A should be properly selected so that A = C + M. (M is the smallest machine allowable positive number from C, if A and C are both integers, M = 1)
  • Assign values ​​to external input variables so that they have different values ​​and signs in each test case and are inconsistent with the values ​​and signs of other variables in the same set of test cases.

LCSAJ refers to a set of codes executed sequentially, ending with a control flow jump. It produces the following 4 layers of coverage:

  • The first layer: statement coverage.
  • The second layer: branch coverage.
  • Third layer: LCSAJ coverage.
  • The fourth layer: two layers of LCSAJ coverage, until N LCSAJ.

Guess you like

Origin blog.csdn.net/Bat_Reality/article/details/123944168