Learn about white box testing (Part 1)

Tram Ho

1. What is white box testing?

A form of testing that testers know the internal structure of the program (source code, data processing, …). The test is based on analysis of the internal structure of the component / system. Check the source code of procedural details (algorithms), logical paths (control flows), program states (data)

Featured:

  • White box testing is based on a specific algorithm, on the internal data structure of the software unit under test to determine whether the software unit is implemented correctly.
  • White box testers must have certain skills and knowledge to understand the details of the code to be tested.
  • It often takes a lot of time and effort if the test level is raised at the integration or system test level.
  • Therefore this technique is mainly used for unit testing. In object-oriented programming, unit testing is testing each task of a certain function class.
  • There are two activities of white box testing: control flow test and data flow test.

2. What is the difference between white box testing and black box testing?

  • Black-box Testing: A form of testing that testers do not need to know how to operate, the source code, and process data inside a component / system. The job to do is to input data (input) and check the results returned as desired or not.
  • White-box Testing is a form of testing whereby testers know the internal structure of the program (source code, data processing, …). The test is based on analysis of the internal structure of the component / system.

3. Flow control graph?

3.1 What elements does the flowchart graph include?

  • Flow / control flow graph is a directed graph of vertices corresponding to statements / statement groups and edges are control lines between statements / statement groups. Elements in control flow graph:
  • The starting point of the program unit
  • The processing block contains statements that are declared or calculated.
  • The decision points correspond to conditional statements in branching or repeating blocks.
  • The junction corresponds to the statements immediately after the branch instruction.
  • End point corresponds to the end point of the program unit

3.2 What is the flow of control graph used for?

The objective of the control flow test method is to ensure that all execution paths of the software units under test are run properly. Unfortunately, in reality, the effort and time to achieve the above goal is huge, even on small software units.

4. Data flow graph

4.1 What elements does a flow chart include?

Definition: The flow graph / data stream of a program / program unit is a directed graph G = <N; E>, with:

  • N is the set of vertices corresponding to the def or c-use statements of the variables used in the program unit. The graph G has two special vertices, the start vertex (corresponding to the def command of the parameter variables) and the end of the program unit.
  • E is the set of edges corresponding to the p-use statements of the variables. Some concepts: Def: is a statement that assigns a value to a variable. Undef: declares the boundary but does not provide a value for it yet. Use: is a statement that uses a variable (calculates or tests conditions). C-use: is a statement that uses variables to calculate the value of another variable. P-use: is a statement that uses variables in conditional expressions (branch statements, iterations, etc.).

4.2 What is the flow chart used for?

Reasons to test the data stream:

  • Make sure the variable is assigned the correct value, that is, we must determine a path of the variable from a starting point where it is defined to the point where the variable is used.
  • Even when assigning the correct value to a variable, the generated values ​​are unlikely to be accurate due to incorrect calculations or conditional expressions (the variable is used incorrectly).

5. Example of white box testing

Request: The function below returns the last element index in x with a value of 0. If none exists, returns the value -1

Enter the following test input:

t1 = (x = {5})

t2 = (x = {0})

t3 = (x = {5, -2,5,7,0})

Flow control graph

The line on the control flow graph corresponds to each of the above inputs

t1 = (x = {5})

Road on control flow graph corresponding to input t1: 1,2,3

t2 = (x = {0})

The line on the control flow graph corresponds to the input t2: 1,2,4,7

t3 = (x = {5, -2,5,7,0})

Road on control flow graph corresponding to input t3: 1,2,4,5,6,4,5,6,4,5,6,4,5,6,7

References:

Daniel Galin. Sofware Quality Assurance – From Theory to Implemtation. Addion Wesley, 2004.

Share the news now

Source : Viblo