1. What is the White-box testing?
- White-box testing is white box testing based on internal structure, design and coding to identify and test software input and output.
- Usually implemented by developers
- Applied for Unit Test, Intergration test
2. White Box test design
2.1 Statement coverage
Formula = (number of statements exercised / Total number of statements) *100%
-> Percentage of instructions executed out of the total number of instructions in the program.
If (a>5) then
print ("a lớn hơn 5")
print("a nhỏ hơn 5")
If there is only 1 TC a = 7 it can run only 4/6 statements (~ 66% statement coverage). It is necessary to add 1 TC that satisfies the condition (a <5) to be able to run to the
print("a nhỏ hơn 5") statement
print("a nhỏ hơn 5") order to run all the commands in the program.
-> So it takes 2 TC to cover the 100% statement coverage in the example above
2.2 Decision coverage (Branch coverage)
Formula = (number of decision outcomes exercised/ Total decision outcomes) *100%
-> Percentage of the number of decision results made over the total number of decision results of the program currently available.
As shown in the example in 2.1. The if statement produces two branches of the results True and False. with TC a = 7 then only run for the result branch True. Now Decision coverage = 1/2 (~ 50%) => It is necessary to add 1 TC for the False result branch to cover the 100% decision coverage.
For the same example, the Statement coverage and Decision coverage are all 2 TCs to cover 100%.
I will add another example to better distinguish the differences between these two types
C = a - 2*b
If (C <0 ) then
print ("C nhỏ hơn 0")
- With only 1 TC a = 10, b = 6, all statements in the program are executed -> Statement coverage reaches 100% with only 1 TC
- As for Decision coverage, TC (a = 10, b = 6) only covers 50% of the result if = True => Need more 1 TC (a = 10, b = 4) to help the program return the results False to Achieve 100% Decision coverage
2.3 Path coverage
Formula = (number of paths exercised/ Total paths it has) *100%
-> Percentage of the number of executable paths on the total number of paths that the program has. (This path must go from the beginning to the end of the program). For example
From left to right corresponds to the total number of 2,3,4 paths that the program can have.
==> The “Statement coverage” standard is just guaranteed to cover all statements so it is quite poor and very easy to miss case
==> The “Decision coverage” standards are stronger than the “Statement coverage” but still a bit weak as it covers only the branches
==> The “Path coverage” standard provides high test coverage because it includes all the statements and branches in the code.
The block diagram results in the corresponding number of TCs for 100% coverage as follows:
- Statement coverage: 1 TC (A = Red, B = Red)
- Decision coverage: 2 TCs (A = Red, B = Red); (A = Green, B = Black)
- Path coverage: 4 TCs (A = Red, B = Red); (A = Red, B = Green); (A = Green, B = Red); (A = Green, B = Green)