Code Coverage Testing: 1. Statement Coverage (Line Coverage)
Code Coverage Testing: 1. Statement Coverage (Line Coverage)
1. AIM
To study and implement the various types of code coverage testing using automated tools in
java environment.
Code coverage analysis is used to measure the quality of software testing, usually using
dynamic execution flow analysis.
Check, whether each statement or line in the program has executed or not
2. Function Coverage
Check, whether each method or function or class in the program has executed or
not
Check, whether each branch of each control structure (like if and case
statements) in the program has executed or not
Check, whether each Boolean sub expression evaluated both to true or false in
the program
I. STATEMENT COVERAGE
It checks whether each statement or line in the program has executed or not
It includes
Return statement, control flow statements (e.g. if, if-else, for, while)
1
Formula
SC= Number of statements exercised
X 100
Total number of statements
Drawbacks
It does not execute false statements
2
I. EXAMPLE OF STATEMENT COVERAGE TESTING
3
2. PROJECT SETTINGS
4
3. PROJECT TREE
5
4. CREATING A NEW CLASS IN ECLIPSE IDE
6
5. SOURCE CODE
(StudentInfo.java)
import java.io.*;
String name;
int id;
String dept;
name=ds.readLine();
id=Integer.parseInt(ds.readLine());
dept=ds.readLine();
input();
System.out.println("-----------------------------");
System.out.println("\tStudent Details");
System.out.println("-----------------------------");
System.out.println("Name\t:"+name);
System.out.println("Id\t:"+id);
System.out.println("Dept\t:"+dept);
7
6. ADDING JUNIT TESTCASE TO EXISTING CLASS
8
7. SET THE NEW NAME TO JUNIT TEST CASE
9
8. METHODS SELECTION TO JUNIT TESTING
10
9. ADDING JUNIT 4
TEST CLASS
(StudentInfoTest.java)
import org.junit.Test;
@Test
obj.result();
11
10. RUNNING TEST CLASS
12
11. GENERAL OUTPUT
13
12. JUNIT TEST RESULT
14
13. RESULT
13.1 SELECT PROJECT PROPERTIES IN ECLIPSE IDE
15
14. COVERAGE RESULT
14.1 RESULT (A)
16
14.2 RESULT (B): OVERALL PROJECT COVERAGE RESULT
17