0% found this document useful (0 votes)
8 views24 pages

Basic Path Testing (1) (1)

Basis Path Testing is a White Box Testing method in software engineering that focuses on defining test cases based on independent paths through a program's control structure to maximize test coverage. It involves constructing a Control Flow Graph, computing Cyclomatic Complexity, identifying independent paths, and designing test cases. Cyclomatic Complexity is a metric that quantifies the number of independent paths in a program, with higher complexity indicating more difficult code to maintain.

Uploaded by

Shishir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views24 pages

Basic Path Testing (1) (1)

Basis Path Testing is a White Box Testing method in software engineering that focuses on defining test cases based on independent paths through a program's control structure to maximize test coverage. It involves constructing a Control Flow Graph, computing Cyclomatic Complexity, identifying independent paths, and designing test cases. Cyclomatic Complexity is a metric that quantifies the number of independent paths in a program, with higher complexity indicating more difficult code to maintain.

Uploaded by

Shishir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Basis Path Testing

Basis Path Testing in software engineering is a White Box


Testing method in which test cases are defined based on
flows or logical paths that can be taken through the program.
This is called source code based testing.The objective of
basis path testing is to define the number of independent
paths, so the number of test cases needed can be defined
explicitly to maximize test coverage
Since this testing is based on the control structure
of the program, it requires complete knowledge of
the program’s structure. To design test cases
using this technique, four steps are followed :
1. Construct the Control Flow Graph
2. Compute the Cyclomatic Complexity of the
Graph
3. Identify the Independent Paths
4. Design Test cases from Independent Paths
Code to CFG
Cyclomatic Complexity
It is an essential metric that measures the complexity of software systems.It
provides a quantitative measure of the number of independent paths through
a program’s source code.
Higher cyclomatic complexity means the code is more difficult to understand
and maintain. Therefore, developers must keep the cyclomatic complexity of
their programs as low as possible to ensure better code quality and
maintainability.
3 Rules
• E - N + 2 [Here, E= Edge, N= Node]
• P + 1 [Here, P= Predicate Node] It means how
many number of decision nodes are present in
CFG.
• No. of Regions [area]
main()
{
int number, index;
1. printf(“Enter a number”);
2. scanf(“%d, &number);
3. index = 2;
4. while(index <= number – 1)
5. {
6. if (number % index == 0)
(a) Draw the CFG graph for the
7. {
program.
8. printf(“Not a prime number”);
(b) Calculate the cyclomatic
9. break;
complexity of the program using all
10. }
the methods.
11. index++;
(c) List all independent paths.
12. }
(d) Design test cases from
13. if(index == number)
independent paths.
14. printf(“Prime number”);
15. } //end main
main()
{
int number, index;
1. printf(“Enter a number”);
2. scanf(“%d, &number);
3. index = 2;
4. while(index <= number – 1)
5. {
6. if (number % index == 0)
7. {
8. printf(“Not a prime number”);
9. break;
10. }
11. index++;
12. }
13. if(index == number)
14. printf(“Prime number”);
15. } //end main
Cyclomatic
complexity
(i) V(G) = e – n + 2 *
p
= 10 – 8 + 2
=4

(ii) V(G ) = Number of predicate


nodes + 1
= 3 (Nodes B, C, and F ) + 1
=4

where n is the number of nodes and e


is the number of arcs/edges. p is the
number of graphs
Independent paths
Since the cyclomatic complexity of
the graph is 4, there will be 4
independent paths in the graph as
shown below:
(i) A-B-F-H
(ii) A-B-F-G-H
(iii) A-B-C-E-B-F-G-H
(iv) A-B-C-D-F-H
# include <stdio.h>
int main()
{
float num,average,sum;
int i,n;
printf("Maximum no. of inputs\n");
scanf("%d",&n);

for(i=1;i<=n;++i)
{
printf("Enter n%d: ",i);
scanf("%f",&num);
if(num<0.0)
break; //for loop breaks
sum=sum+num;
}
average=sum/(i-1);
printf("Average=%.2f",average);
return 0; }

You might also like