Session 8: Unit testing, Module testing and Integration testing

 

Session 8: Develop a set of test cases that will completely test the program in session 7. The test case should be separately developed for Unit testing, Module testing and Integration testing. 

Here we want to generate test cases that will completely test the program given above. This is the program, which takes two matrices as input and generates multiplication of two matrices as output. In order to multiply the two matrices there is a condition for the two matrices, is given below.

·         The no. of columns of the first matrix is equal to the no. of rows of the second matrix, then only it is possible to multiply two matrices, otherwise   it is not possible to multiply two matrices.

Unit Testing

Unit testing is procedure used to verify particular segment of source code is working properly. The main idea about this testing is to generate the test cases for all function or methods. The main goal of unit testing is isolate each part of program and show individual parts are correct. In above program, there are three functions, which perform input, output, and multiplication of two matrices. Let us consider the first function.

 

In main function let us consider

if(c1!=r2)

{

printf("\n unable to multiply");

return;

}

else

{

input(a,r1,c1);

input(b,r2,c2); multiply(a,b,r1,c1,r2,c2); output(a,r1,c1);

output(b,r2,c2);

 

}

The above source code determines the no of columns of the first matrix

equal to the no. of rows of the second matrix then only the multiplication is possible.

 

Test Case

c1

r2

Expected Output

1

3

3

Multiplication of two

matrices is possible

2

3

4

Multiplication of two matrices is impossible

 

This is a segment of input function. if (r1>=10||c1>=10)

{

printf(“\n Unable to enter matrix”); return;

}

else

{

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

}

 

The above code reprgents the no. of rows and no. of columns that are to be given is less than the size of matrix. If the it is not possible to enter the value in the matrix is not greater than its size.

 

Test Case

r1

c1

Expected Output

1

3

3

Entering of matrix

2

10

10

Unable to enter matrix

3

11

11

Unable to enter matrix

 

if (r1>=10||c1>=10)

{

printf(“\n Unable to enter matrix”); return;

}

else

{

for(i=0;i<r2;i++)

{

for(j=0;j<c2;j++) printf("%d\t",a[i][j]); printf("\n");

}

}

The above code is a segment of output function. This code represent the no

.of rows and no. of columns of the matrix is less than the size of the matrix if we gave the no. of rows and no. of columns greater than or equal to size of the array, then we get unexpected values as output

 

Test Case

r1

c1

Expected Output

1

3

3

Shows output of

matrix

2

10

10

Unexpected values

3

11

11

Unexpected values

 

Module Testing

 

Module testing is procedure used to verify the source code is working properly or not. The main idea about this testing is to generate the test cases for all function or methods. In above program, there are three functions, which perform input, output, and multiplication of two matrices. Let us consider the first function.

 

Input Function

 

void input(int a[10][10],int r1, int c1)

{

int i,j;

if (r1>=10||c1>=10)

{

printf(“\n Unable to enter matrix”); return;

}

printf("\n enter 1st matrix elements \n");

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

}

 

In above function there are three inputs. The inputs are no. of rows and no. of columns. The no. of rows and no. of columns can not be greater than the size of the array declared. If the no. of rows and no. of columns is greater than are equal to the size of the array, than it is not possible to enter the values into the array.

 

Test Case

r1

c1

Expected Output

1

3

3

Entering of matrix

2

10

10

Unable to enter matrix

3

11

11

Unable to enter matrix




 

The second function in the above program is given below

 

Output Function

 

void output(int a[10][10], int r2, int c2)

{

int i,j;

if (r1>=10||c1>=10)

{

printf(“\n Unable to enter matrix”); return;

}

else

{

for(i=0;i<r2;i++)

{

for(j=0;j<c2;j++) printf("%d\t",a[i][j]); printf("\n");

} }

}

 

In above function there are three inputs. In this function, the no. of rows and no. of columns that are to be entered is not greater than size of the array.

If the no. of rows and no. of columns is less than the size of the array then it shows that output of the values in the array. If the no. of rows and no. of columns is greater than are equal to the size of the array then the function shows unexpected values because of more than the size of array.

 

Test Case

r1

c1

Expected Output

1

3

3

Shows output of

matrix

2

10

10

Unexpected values

3

11

11

Unexpected values

 

The next function of above program is

 

Multiplication Function

 

void multiply(int a[10][10], b[10][10], int r1, int c1, int r2, int c2)

{

int i,j,k,c[10][10]; for(i=0;i<r1;i++) for(k=0;k<c2;k++)

{ c[i][k]=0;

 

for(j=0;j<c1;j++) c[i][k]=c[i][k]+a[i][j]*b[j][k];

}

printf("\n the multiplication of matrices is \n");

for(i=0;i<r1;i++)

{

for(j=0;j<c1;j++) printf("%d\t",c[i][j]); printf("\n");

}

}

 

In above function there are six inputs.

·         If the no. of rows and no. of columns of the two matrices less than the size of the respected matrix and the column of the first matrix is equal to the row of the second matrix then we get the correct multiplication of two matrices.

·         If the no. of rows and no. of columns is greater than or equal to the size of the respected array and column of the first matrix is equal to the row of the second matrix, then multiplication is possible but we get the unexpected values because of the more than the size of the array.

·         If the no. of rows and no. of columns is less than the size of the respected array and column of the first matrix is not equal to the row of the second matrix, then matrix multiplication is not possible.

 

Test Case

r1

c1

r2

c2

Expected Output

1

3

3

4

4

Unable to multiply

2

3

3

3

3

Multiplication is

possible

3

3

3

10

10

Unable to multiply

4

3

3

11

11

Unable to multiply

5

10

10

3

3

Unable to multiply

6

11

11

3

3

Unable to multiply

7

10

10

10

10

Unable to multiply

8

11

11

11

11

Unable to multiply

 

Integrated Testing

 

Integration testing is the phase of software testing in which individual software modules are combined and tested as a group. Integrating testing as takes as its input, modules that have been checked out by unit testing groups them in larger aggregates, applies this test in order to know whether the system generate the actual output or not.

 

The main aim of this program is to calculate multiplication of two matrices. The multiplication function takes two matrices as input and generates the multiplication as matrix. We must determine the two matrices before the

 

multiplication of two matrices then only we get the multiplication of two matrices. If we don’t determine any of two matrices then we get unexpected values as multiplication of two matrices by taking the default values stored in matrix.

 

Test Case

Matrix a

Matrix b

Expected Output

 

1

 

determined

 

determined

Expected output as multiplication of two

matrices

 

2

 

undetermined

 

determined

Unexpected output as

multiplication of two matrices

 

3

 

determined

 

undetermined

Unexpected output as

multiplication of two matrices

 

4

 

undetermined

 

Undetermined

Unexpected output as

multiplication of two matrices`

 

The main aim of the above program is not achieved if we undetermined any of the two matrices which are taken as input for multiplication of two matrices.

Comments

Popular posts from this blog

Session 4: DFD, ERD, and Data Dictionary

Session 13

Session-1 Scope Statement for the Online Railway Reservation System