Six coverage methods in white box Testing Source Network

Source: Internet
Author: User

Abstract:White box testing, as a common testing method for testers, is becoming more and more important to test engineers. White-box testing is not simply based on the code design case, but based on different testing needs, combined with different testing objects, use the appropriate method for testing. For code logic with different complexity, many execution paths can be derived. Only appropriate test methods can help us find the correct direction from the fog of code. This article introduces six white box testing methods: statement coverage, decision coverage, condition coverage, decision coverage, condition combination coverage, and path coverage.

White box testing Overview

Logical errors and incorrect assumptions are inversely proportional to the possibility that a program path is run. Because we often believe that a logical path cannot be executed, in fact, it may be executed normally. Because pen mistakes in the Code are random and cannot be eliminated, we need to perform a white box test.

White-box testing, also known as structure testing, transparent box testing, logic-driven testing, or code-based testing. White box testing is a test case design method. The box refers to the tested software, and the white box refers to the visible box, you know what is inside the box and how it works.

White-box test cases must be:

· Ensure that all independent paths in a module are used at least once
· Test true and false for all logical values
· Run all cycles within the upper and lower boundary and the operational range
· Check the internal data structure to ensure its effectiveness

Objective of white-box testing: to overwrite the logic path in the software by checking the internal logic structure of the software; to set up checkpoints in different places of the program and check the program status, to determine whether the actual running status is consistent with the expected status.

White-box testing features: Testing Based on the software design specification, strict inspection of internal program details, design test cases for specific conditions, and coverage testing of the software's logical path.

Implementation steps of white box testing:

1. Test plan stage: Develop the test progress according to the requirement specification.
2. Test Design Phase: divide the software structure and design test cases according to the program design specification according to certain standardized methods.
3. test execution phase: Enter the test case to obtain the test result.
4. Test Summary stage: Compare the test results with the expected results of the Code, analyze the cause of the error, and locate and solve the error.

White box testing methods: static methods and dynamic methods are generally divided.

Static analysis is a technique for testing without passing through the execution program. The key function of static analysis is to check whether the software expression and description are consistent, without conflict or ambiguity.

The main feature of dynamic analysis is the analysis of the behavior of a software system before, during, and after execution in a simulated or real environment. Dynamic analysis includes the formal running of programs using specific expected results in a controlled environment. It shows whether a system is in the correct or incorrect status. The most important technology in dynamic analysis is path and branch testing. The six coverage testing methods described below are dynamic analysis methods.

Advantages and disadvantages of white box testing

1. Advantages

· Forces testers to think carefully about software implementation
· Detect every branch and path in the code
· Uncover hidden errors in code
· Complete code Testing
· Optimization

2. Disadvantages

· Expensive
· Failure to detect missing paths and data sensitivity errors in the code
· Do not verify the correctness of specifications

Six coverage Methods

For the convenience of the following example, a program flowchart is provided here. (This article takes an exam question for the 1995 software designer examination as an example. The red letters in the figure represent the program execution path ).

1. Statement Overwrite

1) main features: statement coverage is the minimum structure coverage requirement. statement coverage requires the design of enough test cases so that each statement in the program can be executed at least once.

2) Use Case Design: (if the statement 1-> T in path A is removed, the use case is as follows)

  X Y Path
1 50 50 OBDE
2 90 70 OBCE

3) Advantages: You can obtain test cases from the source code without dividing each judgment expression.

4) Disadvantages: This test method is only applicable to statements explicitly in the program logic. However, it cannot be tested for hidden conditions and potential Implicit logical branches. In this example, if the statement 1-> T is removed, a test path is missing. In the if structure, if the source code does not provide the Execution Branch after else, the statement overwrite test will not consider this situation. However, it cannot be ruled out that the branches other than this type will not be executed, and such errors often occur. For another example, in the Do-While structure, the statement overwrites one of the conditional branches for execution. Obviously, statement overwrite cannot fully reflect the logic operation of multiple branches. It only cares about running once, regardless of other situations.

2. Decision coverage

1) main features: Decision coverage, also known as branch coverage, requires the design of enough test cases to make each decision in the program at least one true value and one false value, that is: each branch in the program must be executed at least once. Each true or false judgment must be performed at least once.

2) Use Case Design:


  X Y Path
1 90 90 OAE
2 50 50 OBDE
3 90 70 OBCE

3) Advantage: The test path that overwrites the statement is almost twice as much as that of the statement. Of course, the test path is more powerful than the statement overwrites. Similarly, the overwrite method has the same simplicity as the overwrite method. You can obtain test cases without dividing each criterion.

4) Disadvantages: Most judgment statements are usually composed of multiple logical conditions (for example, the judgment statement contains AND, OR, and case). If only the final result is determined, ignoring the values of each condition will inevitably omit some test paths.

3. Conditional coverage

1) main features: Condition coverage requires the design of enough test cases, so that each condition in the determination can obtain various possible results, that is, each condition is at least one true value, and one is a false value.

2) Use Case Design:

  X Y Path
1 90 70 OBC
2 40   OBD

3) Advantage: Obviously, the coverage ratio of the condition is higher than the coverage ratio, and the test path is added.

4) Disadvantages: sufficient test cases are required to achieve the coverage of conditions, but the coverage of conditions cannot be guaranteed. Conditional overwrite only ensures that each condition is true at least once, regardless of all judgment results.

4. Decision/condition coverage

1) main features: Design enough test cases to make all possible results of each condition appear at least once, and all possible results of each criterion also appear at least once.

2) Use Case Design:


  X Y Path
1 90 90 OAE
2 50 50 OBDE
3 90 70 OBCE
4 70 90 OBCE

3) Advantages: the decision/condition coverage meets the decision coverage criteria and condition coverage criteria, making up for the shortcomings of both.

4) Disadvantages: the disadvantage of the criterion for determining/covering conditions is the combination of conditions not considered.

5. combined coverage

1) main features: a sufficient number of test cases must be designed to make all possible combinations of conditions in each decision appear at least once.

2) Use Case Design:


  X Y Path
1 90 90 OAE
2 90 70 OBCE
3 90 30 OBDE
4 70 90 OBCE
5 30 90 OBDE
6 70 70 OBDE
7 50 50 OBDE

3) Advantages: the multi-condition coverage criteria meet the criteria for determining coverage, conditional coverage, and decision/condition coverage. The modified judgment/condition overwrite requires that a sufficient number of test cases be designed, so that all possible results of each condition in the determination appear at least once, and all possible results of each decision itself also appear at least once. In addition, each condition is shown to affect the judgment result separately.

4) Disadvantage: the number of test cases is linearly increased.

6. Path coverage

1) main features: Design enough test cases to cover all possible paths in the program.

2) Use Case Design:


  X Y Path
1 90 90 OAE
2 50 50 OBDE
3 90 70 OBCE
4 70 90 OBCE

3) Advantages: This test method can thoroughly test the program, which is wider than the previous five methods.

4) Disadvantages: Because Path coverage requires testing all possible paths (including loops, condition combinations, and Branch selection), a large number of complex test cases need to be designed, this increases the workload exponentially. In some cases, some execution paths cannot be executed, such:
If (! A) B ++;
If (! A) D --;

The two statements actually contain only two execution paths, that is, when A is true or false, the processing of B and D cannot exist, the path overwrite test is considered to contain four real and false execution paths. This not only reduces the test efficiency, but also creates a lot of problems for troubleshooting.

Summary

White-box testing is a widely used logic testing method and a unit testing method driven by the internal logic of the program. Only with a good understanding of the program can we conduct a moderately effective white box test. However, there is uncertainty and infinity in the logic throughout the program, especially for large-scale complex software. Therefore, we cannot trace all the logical paths, even if we do not, it may not bring good luck (we cannot identify program logic rule errors, data errors, or program missing paths ).

To correctly use the white-box test, you must first start with code analysis and select an appropriate override method based on different code logic rules and statement execution conditions. Any efficient test case is applicable to specific test scenarios. Logical testing does not mean one-sided testing of correct results or testing of incorrect results, but overwrites every logical path as much as possible.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.