What is LCSAJ Testing?

LCSAJ stands for Linear Code Sequence and Jump. LCSAJ testing is a white-box testing methodology used to determine the code coverage, i.e., what percentage of the code is executed with the existing test cases. It helps in designing new test cases, which can increase the coverage of the code under test. Once the code coverage reaches a certain level, we can stop the testing. Hence, LCSAJ methodology also helps in determining when to stop the testing of a software.

White-box testing is a software testing technique in which we test the internal structure and the software code under test.

A single LCSAJ has the following three components:

  • Start of the segment, which can be a branch or the start of the program
  • End of the segment, which can be the end of a branch or the end of the program
  • A specific target line

The code executes sequentially from the start of the segment until the end of the segment, and then the control flow breaks the sequential execution and jumps to the target line.

Test Effectiveness Ratio (TER)

Certain metrics are used to check the code coverage. These metrics can help us determine if the testing is enough or not. These metrics are called Test Effectiveness Ratio (TER).

There are three TER metrics:

  • TER-1: Number of statements executed by the test data, divided by the total number of statements

  • TER-2: Number of control-flow branches executed by the test data, divided by the total number of control flow branches

  • TER-3: Number of LCSAJs executed by the test data, divided by the total number of LCSAJs

These TERs are determined using the test data. Moreover, these TERs follow a hierarchy, i.e., if TER-3 is 100%, this means that TER-1 and TER-2 are also 100%.

Example

The code below is written in C++.

Enter input first and then press RUN.

#include <iostream>
using namespace std;
int main() {
int count = 0, sum = 0, input = 0;
while(sum < 100){
cin >> input;
if(input == -1)
break;
sum = sum + input;
count++;
}
cout << "Sum is: " << sum << endl;
cout << "Numbers entered: " << count << endl;
return 0;
}

Enter the input below

Consider the above program, which keeps on taking the input from the user until -1 is entered and displays the sum of all the entered numbers at the end while ensuring that the sum stays below 100.

The LCSAJs for the above code is given in the table below:

LCSAJ Number

Starting of the Segment

Ending of the Segment

Target Line to Transfer Control Flow

1

4

9

11

2

4

13

7

3

4

10

15

4

4

7

15

5

7

7

15

6

7

10

15

7

7

9

199

8

7

13

7

9

11

13

7

Each LCSAJ represents a code segment that executes sequentially from the starting point to the ending point, and then breaks the sequential flow to transfer the control flow.

Each line of code has density, i.e., the number of times a line number appears in LCSAJs. For example, the line number 7 has a density of 7 because it appears in 7 LCSAJs.

100% LCSAJ coverage will be achieved if the test data covers all the above LCSAJs in the table.

Copyright ©2024 Educative, Inc. All rights reserved