Understanding white box testing (part 2)

Tram Ho

As part 1 I have learned about white box testing concepts as well as the difference between white box testing and black box testing … This part I will go into detail about Test coverage techniques in testing. white box

・ Statement coverage (C0) is covered

・ Branch coverage (C1)

・ Path / path coverage

1. Concepts in Test coverage

Statement coverage (C0)

That statement coverage is that we design testcase so that the testcase test suite covers the entire process (statement) called C0. In other words, create a test case by the condition that all the processing is done on once.

Branch coverage (C1) Branch coverage is what we design Testcases so that these testcases must go through the T / F path starting at the decision points (the decision point here is 2 point T / F occurs

Path coverage: path coverage is the way we design test cases so that it covers all paths.

2. Math problem

For the binary search function written in C. The input array v has been sorted in ascending value, where n is the array size, we need to find the array index of the x element. If x is not found in the array, returns -1.

Flow control graph

Path / path coverage all path coverage

path 1: 1-2-3T-4-5F-7F-9-10-13

path 2: 1-2-3T-4-5F-7T-8-11-3T-4-5F-7F-9-10-13

path 3: 1-2-3T-4-5F-7T-8-11-3F-12-13

path 4: 1-2-3T-4-5T-6-11-3T-4-5F-7F-9-10-13

path 5: 1-2-3T-4-5T-6-11-3T-4-5F-7T-8-11-3F-12-13

path 6: 1-2-3T-4-5T-6-11-3F-12-13

path 7: 1-2-3F-12-13

path 8: 1-2-3T-4-5F-7T-8-11-3T-4-5F-7T-8-11-3F-12-13

Statement coverage (C0)

path 5: 1-2-3T-4-5T-6-11-3T-4-5F-7T-8-11-3F-12-13

Branch coverage (C1)

path 1: 1-2-3T-4-5F-7F-9-10-13

path 2: 1-2-3T-4-5F-7T-8-11-3T-4-5F-7F-9-10-13

path 3: 1-2-3T-4-5F-7T-8-11-3F-12-13

path 4: 1-2-3T-4-5T-6-11-3T-4-5F-7F-9-10-13

path 6: 1-2-3T-4-5T-6-11-3F-12-13

path 7: 1-2-3F-12-13

path 8: 1-2-3T-4-5F-7T-8-11-3T-4-5F-7T-8-11-3F-12-13

3. Design test cases

To perform the tests for the above tests we will find the input (x, v, …, n) values ​​that cover each statement.

Tap the test case input to cover the entire statement

Example: Realizing that the input is a test case: t1 = (x = 1, v = {1,2,5,7,9}, n = 5)

The line on the control flow graph corresponds to the input t1: path 4: 1-2-3T-4-5T-6-11-3T-4-5F-7F-9-10-13

=> The output value above is the smallest test case input set to cover the entire statement

Tap the smallest test shift input to cover the turn

TCs 1: t = (x = 5, v = {1,2,5}, n = 3) path 2: 1-2-3T-4-5F-7T-8-11-3T-4-5F-7F -9-10-13

TCs 2: t = (x = 2, v = {2,5,7}, n = 3) path 4: 1-2-3T-4-5T-6-11-3T-4-5F-7F-9 -10-13

TCs 3: t2 = (x = 1, v = {null}, n = 0) path 7: 1-2-3F-12-13

In fact, we will test for specific requirements with the above problem is a specific binary sequence => we do not need to design the entire TCs to cover all the turns but will depend on the requirements to Design TCs kit accordingly

For example, set the input of the smallest test case to cover the entire road with n = 4

path 8: 1-2-3T-4-5F-7T-8-11-3T-4-5F-7T-8-11-3F-12-13 => TCs t = (x = 4, v = {0 , 1,2,3}, n = 4)

path 4: 1-2-3T-4-5T-6-11-3T-4-5F-7F-9-10-13 => TCs t = (x = 2, v = {1,2,5,7 }, n = 4)

path 2: 1-2-3T-4-5F-7T-8-11-3T-4-5F-7F-9-10-13 => TCs t = (x = 5, v = {0,1,2 , 5}, n = 4)

4. Method of carrying out white box testing

4.1 Kinh test (test without running code):

This is the process where we analyze, review each piece of code, try a few sets of TCs, and logically follow each command line to calculate whether the result is as expected. This process takes place before the code is built on the testers / dev to read and understand the code only to determine if the code is correct and not need to run the program.

Defect:

  • Could not test all paths
  • The results are not very accurate due to human calculation and can lead to confusion
  • It is impossible to guarantee that the program has followed the specification and covers all cases
  • Program is wrong due to lack of logic
  • It’s easy to miss special cases if the algorithm loop is complicated

Overcoming the disadvantages of static testing and to ensure that functions and functions work as required Unit tests will be conducted.

4.2 Dynamic testing (testing with tool- requires code execution)

White box testing will usually be done by dev / people who are knowledgeable about code. Dev often uses white box testing during writing Unit tests. This is a process of running code to check that the output is correct for each TCs designed. And Unit tests are usually done with auxiliary tools like Junit (Java framework), PHPUnit (PHP framework), NUnit (.Net framework) etc … these are common tools used for different languages. .

References:

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

Share the news now

Source : Viblo