Transcript
Page 1: Mangesh Software Testing Lab Manual

Software Testing Lab Manual[2014]

Experiment No.01

TITLE: Random test data generation.

PROBLEM:Consider the triangle program that accepts three integers a,b and c, as input. These are taken sides of a triangle. The output of the program is the type of the triangle determined by the three sides: Equilateral, Isosceles, scalene, or not a triangle. Constraints on input are as follows:C1: 1<=a<=200; C2: 1<=b<=200; C3: 1<=c<=200;C4: a<b+c; C5: b<a+c; C6: c<b+a;Write a program in C,C++, Java Programming Language.Generate test cases using random test data generator. Test program using the input generated by Random method. Write percentage for each type of the output generated by given test data.Write your observation for test cases and percentage test cases generated for each type of output.

PROGRAMS:1. STLab1.c#include<stdio.h>#include<conio.h>#include<stdlib.h>//to generate random numbersint generateRandomNumber(){

return rand() % 201; }//main functionvoid main(){

FILE *f=fopen("TestFile.txt","w");int j,a,b,c;for(j=0;j<25;j++){

a=generateRandomNumber();fprintf(f,"%d \n",a);b=generateRandomNumber();fprintf(f,"%d \n",b);c=generateRandomNumber();fprintf(f,"%d \n",c);

}

Veermata Jijabai Technological Institute, Mumbai 1

Page 2: Mangesh Software Testing Lab Manual

Software Testing Lab Manual[2014]

fclose(f);}

2. STLab1TriangleCheck.c#include<stdio.h>//check type of triangle with respect to given inputsvoid TriangleCheck(int ax, int bx, int cx){

if(ax==bx==cx){

printf("\nIt’s Equilateral\n");}else if(cx>(ax+bx)||bx>(ax+cx)||ax>(bx+cx)){

printf("\n It’s not a Triangle\n");}else if(ax==bx || bx==cx || ax==cx){

printf("\n It’s Isoceles\n");}else{

printf("\n It’s Scalene\n");}

}

3.STLabTesting.c#include "STLab1TriangleCheck.c"#include<stdio.h>#include<conio.h>#include<stdlib.h>//main functionint main(){

FILE *fp;fp=fopen("TestFile.txt","r");int a,b,c;while(!feof(fp)){

fscanf(fp,"%d",&a);fscanf(fp,"%d",&b);

Veermata Jijabai Technological Institute, Mumbai 2

Page 3: Mangesh Software Testing Lab Manual

Software Testing Lab Manual[2014]

fscanf(fp,"%d",&c);TriangleCheck(a,b,c);

}fclose(fp);return 0;

}

4. TestFile.txt [ScreenShot]

OBSERVATION:

Veermata Jijabai Technological Institute, Mumbai 3

Page 4: Mangesh Software Testing Lab Manual

Software Testing Lab Manual[2014]

Table 1:Test Case ID A B C Expected

Output1. 41 176 103 Not a triangle2. 169 74 46 Not a triangle3. 21 12 28 Scalene4. 143 77 5 Not a triangle5. 166 144 112 Scalene6. 89 181 83 Not a triangle7. 3 9 30 Not a triangle8. 132 83 153 Scalene9. 91 121 135 Scalene10. 23 20 197 Not a triangle11. 20 18 98 Not a triangle12. 81 60 13 Not a triangle13. 140 169 151 Scalene14. 45 161 93 Not a triangle15. 167 183 186 Scalene16. 41 66 73 Scalene17. 113 34 20 Not a triangle18. 107 100 195 Scalene19. 138 196 80 Scalene20. 93 193 175 Scalene21. 55 20 80 Not a triangle22. 33 87 157 Not a triangle23. 196 98 169 Scalene24. 136 110 87 Scalene25. 11 96 49 Not a triangle

Table 2:

Veermata Jijabai Technological Institute, Mumbai 4

Page 5: Mangesh Software Testing Lab Manual

Software Testing Lab Manual[2014]

Test Case ID Not a Triangle Isosceles Scalene Equilateral

Veermata Jijabai Technological Institute, Mumbai 5

Page 6: Mangesh Software Testing Lab Manual

Software Testing Lab Manual[2014]

1. *2. *3. *4. *5. *6. *7. *8. *9. *10. *11. *12. *13. *14. *15. *16. *17. *18. *19. *20. *21. *22. *23. *24. *25. *

Percentage 52% 0% 48% 0%

CONCLUSION:In this practical, I have written simple codes to generate random numbers to be taken as input by another program as test case data. By observing outputs for each test data, I have filled up two tables showing output for each test case and its percentage for each type of triangle. It was my really interesting to test simple code using C++.

*****

Experiment No.02

Veermata Jijabai Technological Institute, Mumbai 6

Page 7: Mangesh Software Testing Lab Manual

Software Testing Lab Manual[2014]

TITLE: Black Box Testing Techniques:

1. Boundary Value Analysis2. Equivalence Class Partition3. Decision Table

PROBLEM:NextDate :

It is a function of three variables: day, month, yearThis function takes input date and it returns the next date. The constraints on day, month and year integer variables are as follows:

C1 : 1 <= Month <= 12C2: 1 <= Day <= 31C3: 1812 <= Year <= 2020

Write a program in C, C++, Java programming language.

Generate Test Cases using :1) Boundary value Analysis2) Equivalence Class Partition3) Decision Table

Test program using the test cases generated by above techniques.Write percentage for each type of the output generated by the given test cases.

PROGRAM:1. date.cpp #include<iostream>using namespace std;//to check if month having 30 daysbool isMonthOfThirty(int MonthNum){

int i,MonthOfThirty[]={4,6,9,11};for(i=0;i<(sizeof(MonthOfThirty)/sizeof(int));i++){

if(MonthOfThirty[i]==MonthNum){

return true;}

}}

Veermata Jijabai Technological Institute, Mumbai 7

Page 8: Mangesh Software Testing Lab Manual

Software Testing Lab Manual[2014]

//to check if date is validbool isDateValid(int dd,int mm,int yyyy){

if((dd>=1) && (dd<=31)){

if((mm>=1)&&(mm<=12)){

if((yyyy>=1812)&&(yyyy<=2020)){

if(((yyyy%4==0)&&(yyyy%100!=0)) || (yyyy%400==0)){

if((mm==2)&&(dd>29)){

cout<<"Invalid input!!"<<endl;return false;

}}else{

if((mm==2)&&(dd>28)){

cout<<"Invalid input!!"<<endl;return false;

}}if(isMonthOfThirty(mm)){

if(dd>30){

cout<<"Invalid input!!"<<endl;return false;

}}return true;

}else{

cout<<"Invalid input!!"<<endl;return false;

}}

Veermata Jijabai Technological Institute, Mumbai 8

Page 9: Mangesh Software Testing Lab Manual

Software Testing Lab Manual[2014]

else{

cout<<"Invalid input!!"<<endl;return false;

}}else{

cout<<"Invalid input!!"<<endl;return false;

}}

//to find next datevoid getNextDate(int d,int m,int y){

if((d==28) || (d==29) || (d==30) || (d==31)) { d=1; if(m==12) { m=1; y++; } else { m++; } } else { d++; } cout<<"Next Date:"<<d<<"-"<<m<<"-"<<y<<endl;

}

//main functionint main(){

int day,month,year;cout<<"Enter date as an input: [dd mm yyyy]"<<endl;

Veermata Jijabai Technological Institute, Mumbai 9

Page 10: Mangesh Software Testing Lab Manual

Software Testing Lab Manual[2014]

cin>>day>>month>>year;bool validity=isDateValid(day,month,year);if(validity == true){

getNextDate(day,month,year);}return 0;

}

OBSERVATION:(i) Boundary Value Analysis:As there are three inputs in this particular program, We will be using 4n+1 = 4*3+1= 13 Test cases .

Type Day Month Year Expected Output

Normal BVA 1 2 1990 2-2-19902 3 1900 3-3-190030 4 2004 1-5-200431 5 2010 1-6-20107 1 1890 8-1-189015 2 2012 16-2-201220 11 2004 21-11-20045 12 2014 6-12-20145 3 1812 6-3-18127 5 1813 8-5-181315 7 2019 16-7-201917 11 2020 18-11-2020

Normal 7 5 1994 8-5-1994Robust BVA 0 5 1993 Invalid Input!!

32 7 1994 Invalid Input!!7 0 2000 Invalid Input!!5 13 2004 Invalid Input!!4 5 1811 Invalid Input!!6 10 2021 Invalid Input!!

Valid Output % : 68.4%Invalid Output %: 31.6%

(ii) Equivalence Class Partition:[ Valid Output: 33.33% Invalid Output: 66.66%]Variable Type Day Month Year Output

Day < Min -1 5 1994 InvalidNormal 7 5 2004 Valid

Veermata Jijabai Technological Institute, Mumbai 10

Page 11: Mangesh Software Testing Lab Manual

Software Testing Lab Manual[2014]

> Max 32 5 2014 InvalidMonth <Min 7 -1 1900 Invalid

Normal 25 10 1993 Valid> Max 5 13 2001 Invalid

Year <Min 25 5 1811 InvalidNormal 7 10 1994 Valid> Max 5 1 2021 Invalid

(iii) Decision Table:[ Valid Output: 12.5% Invalid Output: 87.5%]Constraints are:C1 : 1 <= Day <= 31C2 : 1 <= Month <=12C3 : 1812 <= Year <= 2020C4 : Leap Year OR Not leap year

Test No. C1 C2 C3 C4 Valid Invalid1 N N N N N Y2 N N N Y N Y3 N N Y N N Y4 N N Y Y N Y5 N Y N N N Y6 N Y N Y N Y7 N Y Y N N Y8 N Y Y Y N Y9 Y N N N N Y10 Y N N Y N Y11 Y N Y N N Y12 Y N Y Y N Y13 Y Y N N N Y14 Y Y N Y N Y15 Y Y Y N Y N16 Y Y Y Y Y N

CONCLUSION:In this experiment, I have studied about the concept of Black Box Testing. And I have used few techniques such as Boundary Value Analysis, Equivalence Class Partition & Decision Table to test simple code in which I am trying to find next date. I have used C language to implement this particular solution.

*****

Experiment No.03

TITLE:

Veermata Jijabai Technological Institute, Mumbai 11

Page 12: Mangesh Software Testing Lab Manual

Software Testing Lab Manual[2014]

Random test data generation.

Veermata Jijabai Technological Institute, Mumbai 12

Page 13: Mangesh Software Testing Lab Manual

Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 13

Page 14: Mangesh Software Testing Lab Manual

Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 14

Page 15: Mangesh Software Testing Lab Manual

Software Testing Lab Manual[2014]

Veermata Jijabai Technological Institute, Mumbai 15

Page 16: Mangesh Software Testing Lab Manual

Software Testing Lab Manual[2014]

Experiment No.04

TITLE:

Veermata Jijabai Technological Institute, Mumbai 16

Page 17: Mangesh Software Testing Lab Manual

Software Testing Lab Manual[2014]

Write a Program In Java To Demonstrate The Working Of Following Statement Controls And Construct Test Cases:1. do…while2. while3. if…else4. switch case

THEORY:In this practical we are going to provide inputs of different types and going to check the expected and observed results . We are going to apply different inputs for control and looping statements to generate test cases.

PROGRAM:1. do…while//TestDoWhile.javaimport java.util.Scanner;

class TestDoWhile{ public static void main(String args[]) { try { Scanner s=new Scanner(System.in); int temp=0; temp=s.nextInt(); do { System.out.println("Value of TEMP is->"+temp); temp--; } while(temp!=0); } catch(Exception e) { System.out.println("Error !!!"); } }}TEST CASES:

Test Case ID temp Expected Output

Output Result

Veermata Jijabai Technological Institute, Mumbai 17

Page 18: Mangesh Software Testing Lab Manual

Software Testing Lab Manual[2014]

1 5 Successful Successful Pass2 -5 Infinite Loop Successful Fail3 -5 Infinite Loop Infinite Loop Pass4 A Invalid Input Invalid Input Pass

2. While//TestWhile.javaimport java.util.Scanner;

class TestWhile{ public static void main(String args[]) { try { Scanner s=new Scanner(System.in); int temp=0; temp=s.nextInt(); while(temp!=0) { System.out.println("Value of TEMP is->"+temp); temp--; } } catch(Exception e) { System.out.println("Error !!!"); } }}

TEST CASES:Test Case ID temp Expected

OutputOutput Result

1 5 Successful Successful Pass

Veermata Jijabai Technological Institute, Mumbai 18

Page 19: Mangesh Software Testing Lab Manual

Software Testing Lab Manual[2014]

2 -5 Infinite Loop Successful Fail3 -5 Infinite Loop Infinite Loop Pass4 A Invalid Input Invalid Input Pass

3. If… Else//TestIfElse.javaimport java.util.Scanner;

class TestIfElse{ public static void main(String args[]) { try { Scanner s=new Scanner(System.in); int a=s.nextInt(); if(a==101) { System.out.println("A is lucky number"); } else { System.out.println("A is not lucky number"); } } catch(Exception e) { e.printStackTrace(); } }}

TEST CASES:Test Case ID a Expected

OutputOutput Result

1 101 Successful Successful Pass

Veermata Jijabai Technological Institute, Mumbai 19

Page 20: Mangesh Software Testing Lab Manual

Software Testing Lab Manual[2014]

2 25 Successful Successful Pass3 abc Invalid Input Successful Fail4 abc Invalid Input Invalid Input Pass5 -43 Successful Successful Pass

4. Switch case//TestSwitch.javaimport java.util.Scanner;

class TestSwitch{ public static void main(String args[]) { try { System.out.println("Enter proper choice: \n 1. Add \n 2. Subtract \n 3. Show \n 4. Exit \n"); Scanner s=new Scanner(System.in); int a=s.nextInt(); switch(a) { case 1: System.out.println("Your choice is to Add"); break; case 2: System.out.println("Your choice is to subtract"); break; case 3: System.out.println("Your choice is to show"); break; case 4: System.out.println("Your choice is to exit"); break; default:System.out.println("Enter proper valid choice!!"); } } catch(Exception e) { e.printStackTrace(); } }}

TEST CASES:Test Case ID a Expected Output Result

Veermata Jijabai Technological Institute, Mumbai 20

Page 21: Mangesh Software Testing Lab Manual

Software Testing Lab Manual[2014]

Output1 1 Successful Successful Pass2 2 Successful Successful Pass3 3 Successful Successful Pass4 4 Successful Successful Pass5 5 Successful Successful Pass6 5 Successful Error Fail7 x Invalid Input Invalid Input Pass8 x Invalid Input Successful Fail

CONCLUSION:In this experiment, I have tried to test simple control statements and looping statements. I have implemented few programs in Java and tested it by applying different types of inputs to generate test cases.

*****

Experiment No.05

TITLE:

Veermata Jijabai Technological Institute, Mumbai 21

Page 22: Mangesh Software Testing Lab Manual

Software Testing Lab Manual[2014]

Program for matrix multiplication . Introspect the causes for its failures and write down the possible reasons for its failures.

THEORY:The program multiplies two matrices and checks for the valid and invalid output with causes of failure being the order of the matrix and entries of the matrix.

PROGRAM:#include<stdio.h>

int main(){

int row1,col1,row2,col2;int a[10][10];int b[10][10];int c[10][10];printf("Enter number of rows and colums of both matrix\n");scanf("%d %d %d %d",&row1,&col1,&row2,&col2);if(row1>0 && row2>0 && col1>0 && col2>0 && col1==row2 && row1<10 &&

row2<10 && col1<10 && col2<10){

int i=0,j=0;printf("Enter first matrix values:\n");for(i=0;i<row1;i++){

for(j=0;j<col1;j++)scanf("%d",&a[i][j]);

}

printf("Enter second matrix values:\n");for(i=0;i<row2;i++){

for(j=0;j<col2;j++)scanf("%d",&b[i][j]);

}

int k=0;for(i=0;i<row1;i++){

for(j=0;j<col2;j++){

int sum=0;for(k=0;k<col1;k++){

Veermata Jijabai Technological Institute, Mumbai 22

Page 23: Mangesh Software Testing Lab Manual

Software Testing Lab Manual[2014]

sum+=a[i][k]+b[k][j];}c[i][j]=sum;

}}int i1=0,j1=0;for(i1=0;i1<row1;i1++){

printf("\n");for(j1=0;j1<col2;j1++)

printf("%d ",c[i1][j1]);}printf("\n");

}else{

printf("Invalid Input\n");}return 1;

}

TEST CASES:Test Case ID

R1 R2 C1 C2 Element Type

Expected Output

Output Remark

1 2 3 3 1 Int Success Success Pass2 2 1 2 3 Int Multiplication

not possibleMultiplication not possible

Pass

3 3 3 3 3 +ve Int Success Success Pass4 3 2 2 3 -ve Int Success Success Pass5 2 3 3 2 +ve/-ve

FloatGarbage Garbage Pass

6 1 2 2 1 Char Multiplication not possible

Success Fail

CONCLUSION:In this experiment, I have examined failure causes by considering variations in rows,columns and contents of the matrix.

Veermata Jijabai Technological Institute, Mumbai 23

Page 24: Mangesh Software Testing Lab Manual

Software Testing Lab Manual[2014]

*****

Experiment No.06

TITLE: Program to calculate the root mean square value with reference to three integers a, b, c. Introspect the causes for its failures and write down the possible reasons for its failures.

Veermata Jijabai Technological Institute, Mumbai 24

Page 25: Mangesh Software Testing Lab Manual

Software Testing Lab Manual[2014]

THEORY:The program calculates the RMS value for the valid and invalid output with causes of failure being the data types of a, b & c.

PROGRAM:#include<stdio.h>#include<math.h>#include<stdlib.h>//to find RMS value of a,b,cint main(){

int a,b,c;int rms;printf("Enter the values for A, B and C:");scanf("%d%d%d",&a,&b,&c);rms=(a*a)+(b*b)+(c*c);printf("RMS -> %f \n",sqrt(rms)); return 0;

}

TEST CASES:Test Case

IDa b c Expected

OutputOutput Remark

1 2 3 4 5.3851 5.3851 Pass2 2.2 3.3 4.4 Int Values

ExpectedInt Values Expected

Pass

3 -2 -3 -4 5.3851 5.3851 Pass

CONCLUSION:In this experiment, I have examined different failure causes by considering various data types and qualifiers for variables a,b and c.

*****

Veermata Jijabai Technological Institute, Mumbai 25