Software Testing and Automation Process: Ananth Karthik Kamalanathan

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 18

HIT 8166 ASSIGNMENT 2, 2011

Software Testing and Automation Process


Assignment 2 ANANTH KARTHIK KAMALANATHAN
6640532

The input files and the output files are in the same folder

Task 1: The tool which I developed for finding the statement coverage criteria to assess the test suit. import java.util.*; import java.io.*; import java.util.StringTokenizer; public class median { public static void main(String[] args) { float N1, N2, N3; int c = 12; String s[] = new String[2]; try{ FileInputStream fstream = new FileInputStream("file.txt"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine = br.readLine();

System.out.println ("Input given to the program is:"+strLine); s= strLine.split("\\s"); N1 = Float.valueOf(s[0].trim()).floatValue(); N2 = Float.valueOf(s[1].trim()).floatValue(); N3 = Float.valueOf(s[2].trim()).floatValue(); float mid; mid = N3; for (int i=0;i<=12;i++) { System.out.println("Line number executed:"+i); } if(N2 < N3) { if(N1 < N2) { mid = N2; c+=7; for (int i=13;i<=19;i++)

{ System.out.println("Line number executed:"+i);}{ System.out.println("100% Statement coverage for n2"); } } else { if(N1 < N3) { mid = N1; c+=7; for (int i=20;i<=26;i++) { System.out.println("Line number executed:"+i);}{ System.out.println("100% Statement coverage for n2"); } }

} } else { if(N1 > N2) { mid = N2; c+=7; for (int i=17;i<=33;i++) { System.out.println("Line number executed:"+i);}{ System.out.println("100% Statement coverage for n2"); } } else { if(N1 > N3) {

mid = N1; c+=7; for (int i=34;i<=40;i++) { System.out.println("Line number executed:"+i);}{ System.out.println("100% Statement coverage for n2"); }}}} System.out.println("Median value:"+mid); System.out.println("No of lines covered:" +c); float percentage = c/46f; percentage = percentage*100; System.out.println("Percentage lines covered:" +percentage+"%"); in.close(); } catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } }}

This program can be run by just giving C:\users\desktop\> median.java


The tool was developed using Java Programming language as specified there is file containing the test suit of the program and another file containing the source code of the program. And the output of the tool will be a file containing the lines which are executed, the statement coverage criteria of N1 or N2 or N3 and, the percentage of the lines which are executed and the median value. The logical flow of the program is very simple
FileInputStream fstream = new FileInputStream("file.txt"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine = br.readLine();

This code reads the file from file.txt And the for loops next to the Def values prints the what all lines are executed in the program and counts it and divides it with the total line numbers and prints it in the output. It also prints the statement coverage criteria of n1 or n2 or n3 which is executed.

Task2:
The given program median.java will not execute all the statements according to its logic. So we keeping the statement coverage criteria as follows. If any one of the inputs N1 or N2 or N3 are given as median in output the following will cover 100% statement coverage. For example: If the test suit in the file.txt is 1.3 1.2 3.6 The following output will be produced, this 100% statement coverage for N1 Input given to the program is:1.3 1.2 3.6 Line number executed:0 Line number executed:1 Line number executed:2 Line number executed:3 Line number executed:4 Line number executed:5 Line number executed:6 Line number executed:7 Line number executed:8 Line number executed:9 Line number executed:10 Line number executed:11 Line number executed:12 Line number executed:20 Line number executed:21 Line number executed:22 Line number executed:23

Line number executed:24 Line number executed:25 Line number executed:26 100% Statement coverage for n2 Median value:1.3 No of lines covered:19 Percentage lines covered:41.304348% For example: If the test suit in the file.txt is 1.2 1.3 3.6 The following output will be produced, this 100% statement coverage for N2 Input given to the program is:1.2 1.3 3.6 Line number executed:0 Line number executed:1 Line number executed:2 Line number executed:3 Line number executed:4 Line number executed:5 Line number executed:6 Line number executed:7 Line number executed:8 Line number executed:9 Line number executed:10 Line number executed:11 Line number executed:12

Line number executed:13 Line number executed:14 Line number executed:15 Line number executed:16 Line number executed:17 Line number executed:18 Line number executed:19 100% Statement coverage for n2 Median value:1.3 No of lines covered:19 Percentage lines covered:41.304348% For example: If the test suit in the file.txt is 1.2 4.3 3.6 The following output will be produced, this 100% statement coverage for N3 Input given to the program is:1.2 4.3 3.6 Line number executed:0 Line number executed:1 Line number executed:2 Line number executed:3 Line number executed:4 Line number executed:5 Line number executed:6 Line number executed:7 Line number executed:8

Line number executed:9 Line number executed:10 Line number executed:11 Line number executed:12 100% Statement coverage for n3 Median value:3.6 No of lines covered:12 Percentage lines covered:26.086956%

Thus the test suits given covers all statement and 100% statement coverage of N1 , N2 and N3 are achieved.

Task 3: Identifying C Use, P Use and Def Use Pairs and summarizing their Data Flow :
The Program median.java: import java.util.*; public class median { public static void main(String[] args) { float N1, N2, N3; N1 = Float.valueOf(args[0].trim()).floatValue(); N2 = Float.valueOf(args[1].trim()).floatValue(); N3 = Float.valueOf(args[2].trim()).floatValue();

float mid; mid = N3; if(N2 < N3) { if(N1 < N2) { mid = N2; } else { if(N1 < N3) {

mid = N1; } } } else { if(N1 > N2) { mid = N2; } else { if(N1 > N3) { mid = N1; } } } System.out.println(mid); } }

C Use:
There is only one System.out.println(mid); c use for N1, N2, N3 It is in line 41 Any values given in the test suit will cover this C use, because it is just going to print the final median value.

P Use: For N1:


In line 13 if(N2 < N3) If the value in the test suit is given as 6 8 2 this p use will be covered. In line 21 if(N1 < N3) If the value in the test suit is given as 6 2 9 this p use will be covered. In line 35 if(N1 > N3) If the value in the test suit is given as 6 8 3 this p use will be covered.

Def-Use: For N1:


Line 13 & 23 are def use pairs of N1 they are mid = N1 & if(N2 < N3) if the value in the test suit is given as 6 8 2 this def use will be covered. Line 21 & 23 are def use pairs of N1 they are mid = N1 & if(N1 < N3) If the value in the test suit is given as 6 2 9 this def use will be covered. Line 35 & 37 are def use pairs of N1 they are mid = N1 & if(N1 > N3) If the value in the test suit is given as 6 8 3 this def use will be covered.

Data Flow of P Use & Def Use of N1:


Line number executed:0 Line number executed:1 Line number executed:2 Line number executed:3 Line number executed:4 Line number executed:5 Line number executed:6

Line number executed:7 Line number executed:8 Line number executed:9 Line number executed:10 Line number executed:11 Line number executed:12 Line number executed:34 Line number executed:35 Line number executed:36 Line number executed:37 Line number executed:38 Line number executed:39 Line number executed:40 100% Statement coverage for n1 Median value:1.1 No of lines covered:19 Percentage lines covered:41.304348%

P Use For N2:


In line 13 if(N2 < N3) If the value in the test suit is given as 6 7 8 this p use will be covered. In line 15 if(N1 < N2) If the value in the test suit is given as 1 2 9 this p use will be covered. In line 29 if(N1 > N2) If the value in the test suit is given as 6 2 1 this p use will be covered.

Def Use: For N2:


Line 13 & 17 are the def use pairs of N2 they are mid=N2 & if(N2 < N3) If the value in the test suit is given as 6 7 8 this def use will be covered. Line 15 & 17 are the def use pairs of N2 they are mid=N2 & if(N1 < N2) If the value in the test suit is given as 1 2 9 this def use will be covered. Line 29 & 31 are the def use pairs of N2 they are mid=N2 & if(N1 > N2) If the value in the test suit is given as 6 2 1 this def use will be covered.

Data Flow of P Use & Def Use of N2:


Line number executed:0 Line number executed:1 Line number executed:2 Line number executed:3 Line number executed:4 Line number executed:5 Line number executed:6 Line number executed:7 Line number executed:8 Line number executed:9 Line number executed:10 Line number executed:11 Line number executed:12

Line number executed:13 Line number executed:14 Line number executed:15 Line number executed:16 Line number executed:17 Line number executed:18 Line number executed:19 100% Statement coverage for n2 Median value:1.4 No of lines covered:19 Percentage lines covered:41.304348%

P Use: For N3:


In line 13 if(N2 < N3) and no other statement is satisfied then this P Use will be covered.

Def Use: For N3:


Line 13 & 12 are Def Use of N3 they are if(N2 < N3) & mid= N3 if if(N2 < N3) and no other statement is satisfied then this def use will be covered.

Data Flow of P Use & Def Use of N3:


Line number executed:0 Line number executed:1 Line number executed:2 Line number executed:3 Line number executed:4 Line number executed:5 Line number executed:6 Line number executed:7 Line number executed:8 Line number executed:9 Line number executed:10 Line number executed:11 Line number executed:12 100% Statement coverage for n3 Median value:1.8 No of lines covered:12 Percentage lines covered:26.086956%

You might also like