1. Definitions
Black box testing - is not concerned about the internal structure of the test / test is based on input and output
White-box testing - testing based on the internal structure
The key white-box testing : coverage
2. The white-box concepts
-
Statement coverage - a test designed to let the object to be measured in all the statements to get test coverage
-
Decision Coverage - designed to allow a test object to be measured in all the determination to get test coverage
-
Condition coverage - a test designed to let the object to be measured in all the conditions to get test coverage
-
Path coverage - a test designed to let the object to be measured in all paths to get test coverage
Image above:
3. Example Problems
Example 1:
solution:
Statement Coverage:
- Statement: each line of the above code is the statement.
- Note THEN behind the connected statement, it is possible not to perform.
- Statement coverage that is designed to test data, so that all statements have been executed.
- To meet the above conditions, as long as two IF determination judged to be "true" can be.
answer:
Branch coverage:
- Branch coverage is determined alias covered. Because the decision may create a branch in the program, like a fork in the road, so that execution of the program go in different directions
- His value is a Boolean type , there are only two possible values: "True" and "False" (true and false).
- Decision coverage, so that all that is judged to have taken all possible values that each decision will take to "true", "false" of all time .
- In this problem there are two decision, that is, "IF" statement, will have to take the test data, so that the two were taken to a genuine IF least of all time.
answer:
2 examples:
solution:
- While loop in question constitutes a branch path of this title code
- Interpretation is determined: when the variable i is not greater than 25, do one thing; when i is greater than 25, to do something else. This determination is "i is greater than 25."
- Most potent satisfy decision coverage, i.e. the minimum number of cycles performed under conditions in which it is determined to take "true", "false" each time .
- I = 25, then take the first loops, while determined to true , the internal logic loop is executed once. After performing i ++ 1, value of i becomes 26, while the determination of false , out of circulation.
answer:
3 examples:
solution:
- The three questions and if a judging all else make up
- To meet the decision coverage, we need to determine all take to "true", "false" of all time .
- Intuitive idea, take four values: n = 0, n = 1, n = 2, n = -1 it can be determined so that all are true and false cover all possible.
- But note that the third after the judgment return statement , the function returns the call itself.
-
This is known as " recursive ", n = 2 is substituted into this data enters the operation function, return statement evolved into the form: return fib (1) + fib (0) + fib (-1), corresponding to taking n = 0, -1 each time
answer:
4. Exercises
Finally, stay a few exercises you can try to answer their own welcome message write down the answers:
1:
2: