Tuesday, 2 January 2018

Source Code Based Test Case Generation

In this short and simple lesson, we are going to discuss techniques in carrying out source code based testing.

Source code based testing is applied when what is available is the source code or the binary for the program.
 
The objective is to check for:
  • Common errors in the source code
  • Failing assert statements for various test inputs
  • Other faults in the code



Techniques
There are three techniques applied in code-based testing that would be discussed in this presentation
  1. Random
  2. Symbolic Execution 
  3. Search-based Testing
  4. Annotation-based Testing

1. Random Testing


In this technique a test input is randomly selected from the given source code. If no errors are found for the selected test input, a different test input is selected. The advantage of this technique is that it is fast and cheap to implement.
A tool used for this technique is the Randoop, used for Java source codes.

2. Annotation-based Testing


This technique works if the source codes contains well-formated annotations that helps to explain the code. These could also be pre and post conditions.
Some of the tools used for annotation-based testing includes QuickCheck and AutoTest



3. Search-based Testing


In this technique, the program is represented as a search space and the objective would be to cover all decision branches in the source code. Some of the tools include EvoSuite

4. Symbolic Execution


Here, symbolic variable instead or real variables are used to generate the test case. Static symbolic execution would fail if the execution part is tool long or has so many constraints. In this case symbolic execution could be combined with concrete executions to create dynamic symbolic execution(DSE).

Other issues with symbolic execution include:
  • Excessive growth of execution paths
  • Complex constructs
  • Complex arithmetic operations and pointer operation