0
5.0kviews
What is the use of code complexity testing ? Also compute code complexity with the help of suitable example.
1 Answer
0
125views

1. Program Statements and Line Coverage (Code Complexity Testing)

i. The most straightforward form of code coverage is called statement coverage or line coverage.

ii. If you’re monitoring statement coverage while you test your software, your goal is to make sure that you execute every statement in the program at least once.

iii. With line coverage the tester tests the code line by line giving the relevant output.

For example

  1. #include<stdio.h>
  2. void main()
  3. {
  4. int i , fact= 1, n;
  5. printf(“enter the number “);
  6. scanf(“%d”, &n);
  7. for(i =1 ;i <=n; i++)
  8. fact = fact * i;
  9. printf (“the factorial of a number is ”%d”, fact);
  10. }

2. Branch Coverage (Code Complexity Testing)

i. Attempting to cover all the paths in the software is called path testing.

ii. The simplest form of path testing is called branch coverage testing.

iii. To check all the possibilities of the boundary and the sub boundary conditions and it’s branching on those values.

iv. Test coverage criteria requires enough test cases such that each condition in a decision takes on all possible outcomes at least once, and each point of entry to a program or subroutine is invoked at least once.

v. Every branch (decision) taken each way, true and false.

vi. It helps in validating all the branches in the code making sure that no branch leads to abnormal behavior of the application.

3. Condition Coverage (Code Complexity Testing)

i. Just when you thought you had it all figured out, there’s yet another complication to path testing.

ii. Condition coverage testing takes the extra conditions on the branch statements into account.

4. Code Complexity: Cyclomatic complexity is metric that quantifies the complexity of a program and provides answers to the questions such as

• 1. Which of the paths are independent? If two paths are not independent then we may be able to minimize the number of tests.

• 2. Is there an upper bound on the number of tests that must be run to ensure that all the statements have been executed at least once?

• In this a program is represented as flow graph. A flow graph consists of nodes and edges.

• Cyclo-matic complexity=Number of predicate nodes(P)+1

Or

• Cyclo-matic complexity=Edges(E)-Nodes(N)+2

enter image description here

In the above flow graph: No. of independent path=2, No. of edges E=4 , No. of nodes N=4

Cyclomatic complexity=E-N+2=4-4+2=2 or

Cyclomatic complexity=P+1=1+1=2

Please log in to add an answer.