Code-based Testing

Introduction :

Code based testing is a way to check whether each and every line of code has been executed. The deal is to find out if there exist any bug in the program, by selecting wisely a set of test cases that can generate the required results by ensuring that coverage criteria is fullfilled. Code based testing is a testing carried out at various levels - code development, code inspection, unit testing. It involves dynamic testing, calculating Cyclomatic complexity, and static testing. Let us discuss each of the components in detail.

code based testing

Dynamic testing :

This type of testing is conducted to ensure that every part of a program is covered systematically. Dynamic testing can also be referred to as control flow based testing, it makes sure that every statement, branch, condition and paths are covered by the test.

  • Statement coverage aims to cover every statement or line of code in a given program's code.
  • Branch coverage aims to check whether the program is switching from one loop to another based on its evaluation.
  • Condition coverage aims to check the validity of conditions in a program.
  • Path coverage checks if the program is able to execute a certain sequence of flow. For example a loop must terminate correctly after executing all the necessary instructions within it.

Cyclomatic Complexity :

This is a mathematical formulae based technique which helps to uncover the facts which may otherwise be a bit tricky to discover. It is the calculation of the number of nodes reached and the subsequent jump to the next node. It is done with the help of a control flow graph and thus helpful in verifying whether all coverage criteria is met.

Static Testing :

This does not involve execution of program's code. This is a technique of analysing the content/code of the application by experts. One may seek the help of dependence graph or syntax tree. It is usually an inspection or a walk through process. Static testing thus involves the following types of analysis methods :

  • Code Inspection - Inspection is carried out with a preplanned approach. It is the most formal type of code review technique which is often led by a moderator. The inspection follows a definite set of rules and checklists that defines the entry and exit criteria. The code is reviewed by referring to some sources like previous document specifications, and at the end of the inspection a report is prepared which enlists all the necessary information that nay be required for further process improvements.
  • Code Walkthrough -This is also a review process in which a programmer leads the review process. Other team members may raise questions related to the development process. The major objective of walkthrough is to learn more about the document under review so that the team members are in a position to understand the document better and also identify the defects.
  • Code Review -this review is conducted by programmers so that they could check each others code in order to find out bugs, if any. It is also called peer review process.
  • Code Audit -An audit process is basically a review process to ascertain that the defined set of rules or protocols have been followed or not. So in this technique, a program's code is analysed in the light of some predefined rules in terms of the specifications, security breaches, violation of programming conventions etc.