White-box test case design method, including white-box test concept, application scenarios, and two use case methods

1. The concept and characteristics of white box testing

1. What is white box testing

Mainly for the test of code logic, covering the code inside the program, it is mainly used in the unit test stage.

Different from black box testing:

1. Black-box testing does not look at the code, black-box testing is designed and input according to business needs

2. The white box test looks at the code, and the white box test is based on the code logic design input

2. Characteristics of white box testing

Pros: High code coverage

Disadvantages: It is difficult to cover all code paths, business functions may not be fully covered, and testing costs are high


2. White box test case design method

1. Static method

Meaning: Do not execute code during the test

method:

  • Desktop Check: Cross Check. The code written by oneself is checked by others, and the development specification and coding requirements must be followed
  • Code Review: Meetings. The code author explains the logical structure, content, etc. of the code, and others check it
  • Code walkthrough: meeting. Use test data to check the direction of the data when the program runs
  • Code scanning tool: check whether the code complies with the coding standard through the tool

2. Dynamic method

Meaning: to execute code during the test

method:

  • logical coverage
    • statement coverage
    • decision coverage
    • condition coverage
    • Judgment condition coverage
    • Condition combination coverage
    • path coverage
  • basic path test

 3. Logic coverage

  • Logical coverage method: program coverage is realized by traversing the program logic structure
  • Coverage: is a means to measure the completeness of the test
  • Convert program code into program flowchart

case:

1. Statement coverage

Statement coverage : design test cases so that each statement in the program is executed at least once

For example : There are 4 executable statements in the case code

 Case (take the flow chart above as an example):

100% statement covered data sentence
{x=3,y=1,magic=2} 1、4
{x=-3,y=-1,magic=-2} 2、3、4

Limitations of statement coverage :

  • Statement Coverage Criterion Weakest
  • Statement coverage cannot accurately judge logical relationship errors in operations

2. Judgment coverage

Decision coverage : also called branch coverage, design test cases so that each judgment "true" and "false" in the program is executed at least once. That is: each branch in the program is executed at least once

For example : there are 2 judgments in the case code and 4 judgment results

 Case (take the flow chart above as an example):

100% verdict covered data if(x>0&&y>0) if(magic<0)
{x=3,y=1,magic=2} T F
{x=-1,y=0,magic=-2} F T

Limitations of decision coverage :

  • As long as the decision coverage standard is satisfied, the statement coverage standard must be satisfied
  • Judgment coverage will ignore the case of or (or) in the condition

3. Condition coverage

Condition coverage : Design test cases so that each condition in the decision is true at least once and false once

For example : there are 2 judgments, 3 conditions, and 6 condition results in the case code

Case (take the flow chart above as an example):

Data with 100% conditional coverage x>0 y>0 magic<0 if(x>0&&y>0) if(magic<0) path
{x=3,y=0,magic=-2} T F T F T a-c-d-f
{x=-3,y=15,magic=2} F T F F F a-c-e-f

Limitations of condition coverage :

  • Condition coverage increases testing of all conditions in a decision over decision coverage
  • Condition coverage does not guarantee decision coverage

4. Judgment condition coverage

Decision condition coverage : Design test cases so that the judgment result (true or false) of each judgment in the tested program is satisfied at least once, and the possible value of each logical condition (true or false) is also satisfied at least once. That is, the criteria of 100% decision coverage and 100% condition coverage are met at the same time

For example : in the case code, there are 2 judgments, 3 conditions, 4 judgment results, and 6 condition results

Case (take the flow chart above as an example):

100% of the data covered by the determination condition x>0 y>0 magic<0 if(x>0&&y>0) if(magic<0) path
{x=3,y=3,magic=2} T T F T F a-b-e-f
{x=-3,y=0,magic=-2} F F T F T a-c-d-f

Limitations of decision condition coverage :

  • Satisfying the decision coverage criteria must be able to meet the condition coverage, decision coverage and statement coverage
  • Judgment condition coverage will ignore the case of taking or (or) in the condition

5. Condition combination coverage

Condition Combination Coverage : Design test cases so that all possible combinations of condition outcomes in each decision in the program under test are executed at least once

For example : there are 2 judgments and 3 conditions in the case code (judgment 1 has 2 conditions, judgment 2 has one condition), the combination of conditions for judgment 1 is 4, and the combination of conditions for judgment 2 is 2

Case (take the flow chart above as an example):

Data covered by 100% condition combinations x>0 y>0 magic<0 if(x>0&&y>0) if(magic<0) path
{x=3,y=0,magic=-2} T F T F T a-c-d-f
{x=-3,y=15,magic=2} F T F F F a-c-e-f
{x=3,y=3,magic=2} T T F T F a-b-e-f
{x=-3,y=0,magic=-2} F F T F T a-c-d-f

Limitations of Condition Combination Overrides :

  • Condition combination coverage can satisfy decision coverage, condition coverage, decision condition coverage, including statement coverage
  • Conditional combination coverage does not guarantee that all paths are executed

6. Path coverage

Path coverage : design test cases to cover all possible paths in the program

For example : there are 4 paths in the case code

Case (take the flow chart above as an example):

Data covered by 100% condition combinations x>0 y>0 magic<0 if(x>0&&y>0) if(magic<0) path
{x=3,y=3,magic=-2} T T T T T a-b-d-f
{x=-3,y=3,magic=-2} F T T F T a-c-d-f
{x=3,y=3,magic=2} T T F T F a-b-e-f
{x=-3,y=15,magic=2} F T F F F a-c-e-f

Limitations of path coverage :

  • Path coverage can thoroughly test the program, which is wider than the previous five types of coverage
  • Satisfying the path coverage does not necessarily satisfy the conditional coverage, and it cannot satisfy the conditional combination coverage

Fourth, the basic path test method

1. What is the basic path test method

        On the basis of the program control flow chart, by analyzing the loop complexity of the program, a set of basic executable paths is derived to design test cases

2. Basic path test method steps

  1. Draw the program control flow chart according to the code
  2. Computing the Cyclomatic Complexity of a Program
  3. export executable path
  4. design test cases

2.1 Draw the program flow chart according to the code

2.2 Cyclic complexity of calculation program 

There are three methods:

  • The number of regions in the flow graph corresponds to the complexity of the ring. The number of regions shown in the above figure is 4
  • Given the cyclomatic complexity V(G) of a flow graph G, it is defined as V(G)=E-N+2, where E is the number of edges in the flow graph, and N is the number of nodes in the flow graph. As shown in the figure above: V(G)=10-8+2=4
  • Given the cyclomatic complexity V(G) of the flow graph G, it is defined as V(G)=P+1, where P is the number of decision nodes in the flow graph G. As shown in the figure above: V(G)=3+1=4

2.3 Export executable path

  • Path 1: 4-14
  • Path 2: 4-6-7-14
  • Path 3: 4-6-9-12-13-4-14
  • Path 4: 4-6-9-10-13-4-14

2.4 Design test cases

Test Data expected outcome coverage path
iRecordNum=0 x=0 4-14
iRecordNum=1, iType=0 x=2 4-6-7-14
iRecordNum=1, iType=1 x=10 4-6-9-12-13-4-14
iRecordNum=1, iType=2 x=20 4-6-9-10-13-4-14

V. Summary

  • White box testing is mainly used in the unit testing phase
  • First static, then dynamic
  • Design use cases generally use basic path testing, and key modules use multiple coverage standards

Guess you like

Origin blog.csdn.net/ouihsiad/article/details/127782752