Testing – Programmerbay https://programmerbay.com A Tech Bay for Tech Savvy Mon, 19 Sep 2022 18:06:44 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://programmerbay.com/wp-content/uploads/2019/09/cropped-without-transparent-32x32.jpg Testing – Programmerbay https://programmerbay.com 32 32 Difference between Statement Coverage and Branch Coverage in Tabular form https://programmerbay.com/distinguish-between-statement-coverage-and-branch-coverage/ https://programmerbay.com/distinguish-between-statement-coverage-and-branch-coverage/#respond Wed, 14 Sep 2022 16:20:57 +0000 https://programmerbay.com/?p=5540 In software testing, code coverage is a measure that determines how much code in a program is successfully tested. It provides various methods such as branch coverage, statement coverage,decision coverage, FSM coverage and more. In this article, we’ll be discussing branch coverage and statement coverage.

Branch coverage and Statement Coverage are form of white box testing techniques.

The main difference between them is, the aim of statement coverage is to traverse all statements at least once, whereas the goal of branch coverage it to traverse all the branches at least once.

Difference between Statement Coverage and Branch Coverage in Tabular form

Statement CoverageBranch Coverage
Statement coverage is a technique which aims to cover all the statements at least once by executing the programThe main goal of branch coverage is to cover branches at least once (true and false)
It focuses on covering all statements or lines of a programIt focuses on covering branches, both conditional and unconditional
It is weaker criteria than branch coverage as test cases that cover all statements may not cover all the branchesIt is stronger criteria than branch coverage that cover all branches would also cover all the statements too
Coverage Measurement,
Statement coverage = (Total Statements covered/Total Statements )* 100
Coverage Measurement,
Branch coverage = (Total branch covered/Total Branches )* 100

Statement Coverage

It is also termed as Line coverage.
The goal of this technique is to cover all the statements at least once by executing the program.

It requires test cases that make possible to run all the statement consisting of the program in order to achieve 100% coverage. It only assures that all the statements have executed but not assures whether all the paths have covered or not.

For example:

READ A
IF A == 10
THEN
PRINT I am True
ElSE
PRINT I am False
ENDIF

 

Test case #1 ( A = 5 )

Statement coverage = (Total Statements covered/Total Statements )* 100

=(5/7)*100

statement coverage

In the above code, 71.5% statement coverage is achieved by test case #1.

Test case #2 ( A = 10 )

Statement coverage = (Total Statements covered/Total Statements )* 100

=(5/7)*100

statement coverage

Again, 71.5% statement coverage is covered, and altogether these two test cases executed all the possible paths with 71.5% statement coverage each.

Executing every statement of a program helps in finding faults, unreachable or useless statements.

Branch Coverage

In a flow graph, an arrow represents edges and counting a statement as a node, where two nodes are connected with an edge.

A diamond symbol represents the decision node where more than one edges are present in an outgoing manner which is termed as Branches.

The main aim of branch coverage is to cover all the branches ( two separate paths) at least once (true and false).
Branch Coverage is a structurally based technique that checks both conditional and unconditional branches.

Branch  coverage = (number of executed branches/ total number of branches) * 100

For example:

READ A 
IF A == 10
THEN 
PRINT I am True 
ElSE 
PRINT I am False 
ENDIF

 

branch coverage corrected

Branches:

  • 2,5,6,7
  • 2,3,4,7

To cover all the branches we would require 2 test cases:

Test case #1 ( A = 12 )

Branch coverage = (Total branch covered/Total Branches )* 100

=(1/2)*100

branch coverage 50

In the above code, 50% branch coverage is achieved by test case #1.

Test case #2 ( A = 10 )

Branch coverage = (Total branch covered/Total Branches )* 100

=(1/2)*100

branch coverage 50

Again, 50% branch coverage is achieved by test case #2.

Altogether these two test cases executed all the possible branches with 50% branch coverage each.

 

]]>
https://programmerbay.com/distinguish-between-statement-coverage-and-branch-coverage/feed/ 0
Design the test cases and test the program of Previous Date problem by using Robustness Testing https://programmerbay.com/design-the-test-cases-and-test-the-program-of-previous-date-problem-by-using-robustness-testing/ https://programmerbay.com/design-the-test-cases-and-test-the-program-of-previous-date-problem-by-using-robustness-testing/#respond Fri, 20 Sep 2019 06:50:35 +0000 https://programmerbay.com/?p=5254 In previous date problem, we will test our code using Robustness Testing to check whether it can provide expected the previous date as an output or not. We are considering interval [2000,2050]  for year, [1,31] days for date, [1,12] for month. If we look closely, we require to figure out for given year input whether it is a leap year or not.

We will be using Robustness Testing to generate test cases.  The expected output can be  [Invalid input, Invalid date, previous Date].

Program

Here is the “previous date problem” program along with its tested test cases.

Robustness Testing

So, there will be 6N+ 1 test cases that is 6*3 +1 =19 in this case as we are using Robustness Testing.

Test IDDateMonthYearExpected OutputProgram OutputTest Outcome
1062025Invalid InputInvalid InputPass
216202531-5-202531-5-2025Pass
32620251-6-20151-6-2015Pass
4306202529-6-201529-6-2015Pass
53162025Invalid DateInvalid DatePass
63262025Invalid InputInvalid InputPass
71502025Invalid InputInvalid InputPass
8151202514-1-202514-1-2025Pass
9152202514-2-202514-2-2025Pass
101511202514-11-202514-11-2025Pass
111512202514-12-202514-12-2025Pass
1215132025Invalid InputInvalid InputPass
13 1561999Invalid InputInvalid InputPass
14156200014-6-200014-6-2000Pass
15156200114-2-200114-2-2001Pass
16156204914-6-204914-6-2049Pass
17156205014-6-205014-6-2050Pass
181562051Invalid InputInvalid InputPass
19156202514-6-202514-6-2025Pass

 

]]>
https://programmerbay.com/design-the-test-cases-and-test-the-program-of-previous-date-problem-by-using-robustness-testing/feed/ 0
Design the test cases and test the program of Previous Date problem by using Boundary Value Analysis https://programmerbay.com/design-the-test-cases-and-test-the-program-of-previous-date-problem-by-using-boundary-value-analysis/ https://programmerbay.com/design-the-test-cases-and-test-the-program-of-previous-date-problem-by-using-boundary-value-analysis/#respond Fri, 20 Sep 2019 06:22:04 +0000 https://programmerbay.com/?p=5253 In this, we will test our program to check whether it can give the previous date as an output or not. We are supposing interval [2000,2050]  for year, [1,31] days for date, [1,12] for month. If we observe closely, we require to figure out whether the year input is a leap year or not between the selected year interval.

We will be applying Boundary Value Analysis to generate test cases.  The expected output can be  [Invalid date, previous Date].

Program:

#include<conio.h>
#include<stdio.h>
void main()
{
	int month,date,year, valid=-1,leap_year=-1;
	printf("please enter a date = ");
	scanf("%d",&date);
		printf("please enter a month = ");
	scanf("%d",&month);
		printf("please enter a year = ");
	scanf("%d",&year);
	if((date>0 && date<=31)&&(month>=1 && month<=12)&&(year>=2000 && year<=2050))
	{
	// finding given input is a leap year or not
	if((year%4)==0)
	{
		leap_year=1;
    if((year%100)==0)
    {
	if((year%400)==0)
	{
		leap_year=1;	
	}
	else
	{
	leap_year=-1;	
	}
}
}
if(month==2 && leap_year==1 && date >29)
valid=-1;
else if(month==2 && leap_year==-1 && date >28)
valid=-1;
else 
valid=1;
}

if((month==6 || month==4||month==9||month==11) && date>30)
valid=-1;

// validating & finding output


if(valid==1)
{
	printf("Entered date = %d-%d-%d",date,month,year);

if(date==1)
{
if(month==1)
{
date=31;
month=12;
year--;
}
else if(leap_year=1 && month==3)
{
	date=29;
	month--;
}
else if(leap_year==-1 && month==3)
{
	date=28;
	month--;
}
else if(month==2||month==4||month==6||month==8||month==9||month==11){
	date=31;
	month--;
}else{
	date=30;
	month--;
}
}
else{
	
	date--;
}
printf("\nPrevious date = %d-%d-%d \n",date,month,year);
}
else
printf("\n Not a valid date");

getch();
}

So, there will be 4N+ 1 test cases that is 4*3 +1 =13 in this case as we are using boundary value analysis.

Test IDDateMonthYearExpected OutputProgram OutputTest Outcome
116202531-5-202531-5-2025Pass
22620251-6-20151-6-2015Pass
3306202529-6-201529-6-2015Pass
43162025Invalid DateInvalid DatePass
5151202514-1-202514-1-2025Pass
6152202514-2-202514-2-2025Pass
71511202514-11-202514-11-2025Pass
81512202514-12-202514-12-2025Pass
9156200014-6-200014-6-2000Pass
10156200114-2-200114-2-2001Pass
11156204914-6-204914-6-2049Pass
12156205014-6-205014-6-2050Pass
13156202514-6-202514-6-2025Pass

Testing the program:

Invalid Date:

previous date

Previous Date:

previous date 1

]]>
https://programmerbay.com/design-the-test-cases-and-test-the-program-of-previous-date-problem-by-using-boundary-value-analysis/feed/ 0