Presentation is loading. Please wait.

Presentation is loading. Please wait.

WHITE BOX TESTING IS4500 Copyright © 2012 by The Cathris Group and Martin J. Schedlbauer. All Rights Reserved. Do Not Duplicate or Distribute Without Written.

Similar presentations


Presentation on theme: "WHITE BOX TESTING IS4500 Copyright © 2012 by The Cathris Group and Martin J. Schedlbauer. All Rights Reserved. Do Not Duplicate or Distribute Without Written."— Presentation transcript:

1 WHITE BOX TESTING IS4500 Copyright © 2012 by The Cathris Group and Martin J. Schedlbauer. All Rights Reserved. Do Not Duplicate or Distribute Without Written Consent of the Author. www.cathris.com · info@cathris.com

2 Objectives Upon completion of this chapter you will be able to: ◦ Create test cases based on statement and branch coverage ◦ Calculate statement and branch coverage metrics v1.01 2 Solution Validation & Testing

3 What is White Box Testing? The basis for white box testing is the test object’s source code. It is a code-based testing technique and therefore the source code must be available and it must be possible to manipulate the code by adding test “hooks”. The general idea is to exercise every part of the code of the test object at least once.

4 White Box Testing Techniques Flow-oriented test cases that represent the program logic are identified and all paths are executed. The expected result is generally what the programmer wrote not necessarily what the requirements stated.

5 What is Tested? The overall goal of WBT is to achieve coverage of the entire code base: ◦ Statements ◦ Decisions and branches ◦ Conditions ◦ Paths

6 Statement Testing This analysis focuses on each statement of the test object. Code is first translated into a control flow graph: ◦ Branches ◦ Sequential statements are a single block as statement execution is guaranteed ◦ All statements must be executed

7 Test Cases Map out the sequence of control and each path becomes a test case. Ensure that all paths are covered.

8 C0 Test Completion Criterion The completion criteria for tests can be defined by the following metric: 100% coverage is difficult to achieve and may be too expensive. ◦ For example, how would you trigger all exception handling catches? Statement Coverage = (number of executed statements / total number of statements) * 100%

9 Dead Code Analysis If complete coverage of all statements is required and some statements cannot be triggered, then that means there is code that is unreachable (“dead code”).

10 Branch Testing & Coverage In this form of testing, the execution of each statement is not considered. Instead focus is directed to the execution of branches (decisions). Testing should ensure that each branch is taken following a decision. For loops testing should ensure execuction of the body as well as fall-through.

11 C1 Test Completion Criterion Analogous to the statement coverage, the degree of coverage for branch coverage is defined as: Branch Coverage = (number of executed branches / total number of branches) * 100%

12 Code Analysis Example 1 private static Point2D.Double calcPathLine(Point s, Point e) { double m = 0.0, b = 0.0; m = (double)(e.y - s.y) / (double)(e.x - s.x); if (Double.isInfinite(m)) if (m < 0.0) m = (-1.0) * Double.MAX_VALUE; else m = Double.MAX_VALUE; b = s.y - (m * s.x); if (Double.isInfinite(b)) if (b < 0.0) b = (-1.0) * Double.MAX_VALUE; else b = Double.MAX_VALUE; return new Point2D.Double(m, b); }

13 Code Analysis Example 2 double calc_price ( double baseprice, double specialprice, double extraprice, int extras, double discount) { double addon_discount; double result; if (extras >= 3) addon_discount = 10; else if (extras >= 5) addon_discount = 15; else addon_discount = 0; if (discount > addon_discount) addon_discount = discount; result = baseprice / 100.0 * (100 – discount) + special_price + extraprice / 100.0 * (100 – addon_discount) return (result) }

14 Control Flow Graph

15 Test Cases Which edges in the control flow graph were executed? What is the branch coverage? Does running test 02 improve branch coverage? What additional test cases do you need to improve branch coverage? Which cases would you need to achieve 100% coverage? // test case 01 price = calc_price(10000.0,2000.0,1000.0,3,0); test_ok = test_ok && (abs(price-12900.0) < 0.01; // test case 02 price = calc_price(25500.0,3450.0,6000.0,6,0); test_ok = test_ok && (abs(price-34050.0) < 0.01;

16 Summary In this module we learned that: ◦ White box testing complements black box testing 16 Solution Validation & Testing v1.01


Download ppt "WHITE BOX TESTING IS4500 Copyright © 2012 by The Cathris Group and Martin J. Schedlbauer. All Rights Reserved. Do Not Duplicate or Distribute Without Written."

Similar presentations


Ads by Google