In previous article Software Testing Techniques, I have explained about the testing techniques overview.
In this article we will discuss about Specification Based Testing or White Box test techniques
White-box testing
- In white box testing, an input must still produce the correct result in order to pass, but now we are also concerned with whether or not the process worked correctly.
- “Testing based on an analysis of the internal structure of the component or system.” [ISTQB Glossary]
White-box test design technique:
- “Procedure to derive and/or select test cases based on an analysis of the internal structure of a component or system.” [ISTQB Glossary]
Following are the white box test design techniques
- Statement Testing
- Decision Testing
- Condition Testing
- Multiple Condition Testing
Statement Testing
Ref: Software Engineering Competence Center
Coverage Items:
- Executable Code Statement
Structure Element:
- Code Statement
Coverage Measure:
- All executable statements must be exercised at least once during test case execution
Thoroughness:
- The minimum level of analysis of code coverage. Does not consider different statement combinations or execution paths.
Consider the following code sample:
READ income;
tax_perc = 0.15;
IF income < 5000 THEN
tax_perc = 0;
END IF;
tax_amt = income * tax_perc;
READ income;
tax_perc = 0.15;
IF income < 5000 THEN
tax_perc = 0;
END IF;
tax_amt = income * tax_perc;
Test Case 1: income = 6000, statement coverage = (4 / 5) *100 = 80%
Test Case 2: income = 3000, statement coverage = (5 / 5) *100 = 100%
One test case is enough to achieve 100% code coverage for this code.
Exercise: what is the minimum number of test cases to achieve 100% statement coverage for the following code:
READ income;
IF income < 5000 THEN
tax_perc = 0;
ELSE
tax_perc = 0.15;
END IF;
tax_amt = income * tax_perc;
IF income < 5000 THEN
tax_perc = 0;
ELSE
tax_perc = 0.15;
END IF;
tax_amt = income * tax_perc;
No single test case is enough to achieve 100% code coverage for this code. At least two test case are needed (e.g. income = 2000, income = 7000)
Decision Testing
Coverage Items:
- Decision outcomes
- IF statement, Loop control (DO-WHILE, REPEAT-UNTIL), CASE statement
- All decision outcomes must be exercised at least once during test case execution
- Stronger than statement coverage. 100% decision coverage guarantees 100% statement coverage but not vice versa.
READ income;
tax_perc = 0.15;
IF income < 5000 THEN
tax_perc = 0;
END IF;
tax_amt = income * tax_perc;
Test Case 2: income = 3000,
Statement coverage = 100%
Decision coverage = (1 / 2) * 100 = 50%
A possible defect overlooked by this test case is when the READ statement doesn't work causing the IF statement to always give TRUE.
Two test cases are necessary to achieve 100% decision coverage (e.g. 3000, 6000)
Post a Comment