0% found this document useful (0 votes)
570 views

Basis Path Testing Example

The document discusses basis path testing using an example algorithm to calculate shipping charges. It provides the steps to: 1) Draw the flow graph of the algorithm. 2) Determine the cyclomatic complexity which gives the number of independent paths. 3) Derive the basis set of independent paths through the graph. 4) Prepare test cases that execute each basis path to test all nodes and edges.

Uploaded by

Kwang Su Wei
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
570 views

Basis Path Testing Example

The document discusses basis path testing using an example algorithm to calculate shipping charges. It provides the steps to: 1) Draw the flow graph of the algorithm. 2) Determine the cyclomatic complexity which gives the number of independent paths. 3) Derive the basis set of independent paths through the graph. 4) Prepare test cases that execute each basis path to test all nodes and edges.

Uploaded by

Kwang Su Wei
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Basis Path Testing Example

Step 1: Draw the flow graph for the algorithm. The example procedure below shows how the algorithm statements are mapped into graph nodes, numbered on the left.
public double calculate(int amount) { -1-1-2double rushCharge = 0; if (nextday.equals("yes") ) { rushCharge = 14.50; } double tax = amount * .0725; if (amount >= 1000) { shipcharge = amount * .06 + rushCharge; } else if (amount >= 200) { shipcharge = amount * .08 + rushCharge; } else if (amount >= 100) { shipcharge = 13.25 + rushCharge; } else if (amount >= 50) { shipcharge = 9.95 + rushCharge; } else if (amount >= 25) { shipcharge = 7.25 + rushCharge; } else { shipcharge = 5.25 + rushCharge; }

-3-3-4-5-6-7-8-9-10-11-12-

-13-

-14- total = amount + tax + shipcharge; -14- return total; } //end calculate

Here is a drawing of the flowgraph.

Step 2: Determine the cyclomatic complexity of the flow graph.

V(G) = E - N + 2 = 19 - 14 + 2 = 7 This tells us the upper bound on the size of the basis set. That is, it gives us the number of independent paths we need to find. Step 3: Determine the basis set of independent paths. Path 1: Path 2: Path 3: Path 4: Path 5: Path 6: Path 7: 1 - 2 - 3 - 5 - 7 - 9 - 11 - 13 - 14 1 - 3 - 4 - 14 1 - 3 - 5 - 6 - 14 1 - 3 - 5 - 7 - 8 - 14 1 - 3 - 5 - 7 - 9 - 10 - 14 1 - 3 - 5 - 7 - 9 - 11 - 12 - 14 1 - 3 - 5 - 7 - 9 - 11 - 13 - 14

Note: This basis set is not unique. There are several different basis sets for the given algorithm. You may have derived a different basis set. The basis set "covers" all the nodes and edges in the algorithm. Step 4: Prepare test cases that force execution of each path in the basis set. path 1 2 3 4 5 6 7 nextday amount yes no no no no no no 10 1500 300 150 75 30 10 expected result 30.48 ????.?? 345.75 174.125 90.3875 39.425 15.975

Recommended: Use the Basis Path Worksheet to record your test cases. Wrinkles

a return statement in the middle of a block is treated as though there were an arc to the end. Otherwise it's an extra terminal symbol. a return of a boolean expression is treated as an if statement. Exceptions are messy as they can potentially cause interruption in flow of control at any statement in the block. It may be easiest to simply choose a single arbitrary exception point. complex conditions are represented as a separate node for each condition.

Flowgraph for boolean AND

Flowgraph for boolean OR

Note: Basis Path testing is not sufficient in itself. It must be supplemented with other white box techniques or a formal correctness proof.

You might also like