4.3 White-Box Test Techniques Flashcards
What two code-related white-box test techniques are covered in the Foundation syllabus?
Statement testing and Branch testing.
Define Statement Testing.
Coverage items are executable statements. The aim is to test individual statements in the code with test cases until an acceptable level of coverage is achieved. Coverage is measured as the number of statements divided by the total number of executable statements in the code.
When 100% statement coverage is achieved, it ensures that all executable statements in the code have been exercised at least once. This in turn means that every statement with a defect will be executed - does this mean all defects will be found?
If every statement with a defect will be executed, then those tests may cause a failure demonstrating the presence of a defect.
However, in some cases, simply exercising the defective statement will not generate a failure or result in a detected defect. Also, exercising all statements individually does not ensure that all decision logic has been tested.
What is a branch in the context of testing code?
A branch is a transfer of control between two nodes in the control flow graph, which shows the possible sequences in which source code statements are executed in the test object. Each transfer of control can be either unconditional (straight-line code) or conditional (a decision outcome).
Describe Branch Testing and Branch coverage.
In branch testing, coverage items are branches, and the aim is to design test cases to exercise branches in the code until an acceptable level of branch coverage is achieved. Coverage is measured as the number of exercised branches divided by the total number of branches.
When 100% branch coverage is achieved, all branches in the code, unconditional and conditional, are exercised by test cases. Will this capture all defects?
No. exercising a branch with a test case will not detect defects in all cases. For example, it may miss defects requiring the full execution of a specific path in the code.
Describe possible test outcomes for conditional branches.
Conditional branch test results typically correspond to true / false from an “if…then” decision, an outcome from a switch/case statement, or a decision to continue or exit from a loop.
Is Branch coverage or Statement coverage stronger?
Branch coverage subsumes and contains statement coverage. If 100% branch coverage is achieved, then 100% statement coverage is also achieved, but not vice versa.
What are the biggest strength and weakness of white-box testing?
A fundamental strength of white-box testing is that the entire software implementation is taken into account during testing, which facilitates defect detection even when the software spec is outdated or incomplete.
The corresponding weakness is that, since we’re not concerned with specifications in white-box testing, it may not detect missing requirements or features.
Is white-box testing suitable for static testing?
Yes, these techniques are well suited to reviewing code that is not yet ready to run, as well as pseudocode and other high level or top-down logic which can be modeled using a control flow graph.
Does black-box testing by itself provide a measure of code coverage?
No, it does not. Only white-box testing techniques can provide an objective coverage measure for code branches and statements. These techniques also provide the information needed to allow additional tests to be generated to increase that coverage and confidence in the code.