GOVERNMENT ENGINEERING COLLEGE BHARATPUR
SOFWARE TESTING AND VALIDATION LAB
(Subject Code: 8CS4-22)
Submitted By: Submitted To:
Kushagra Agrawal Dr. Ankit Panch
22EELCS025 Assistant Professor
4th Year / 8th semester Department Of C.S.E
Experiment 1(a)
AIM: Write a program that calculates the area and perimeter of a circle.
Also find the Coverage & Test Cases of that program using JaButi Tool.
Program:
import [Link];
public class Circle {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
double radius = [Link]();
if(radius >= 0) {
double area = [Link] * radius * radius;
double perimeter = 2 * [Link] * radius;
[Link]("Area = " + area);
[Link]("Perimeter = " + perimeter);
} else {
[Link]("Invalid Input");
}Test Cases:
Test Case No. Input (Radius) Expected Output (Area) Expected Output (Perimeter)
TC1 1 3.14 6.28
TC2 2 12.56 12.56
TC3 0 0 0
TC4 -5 Invalid Input Invalid Input
Coverage Type Status
Statement Coverage 100%
Branch Coverage 100%
All statements and both conditions (valid & invalid input) are executed, hence full coverage is achieved.
Experiment 1(b)
Aim:To write a Java program to read first name and last name from console and match with expected
result, and design test cases.
Program:
import [Link];
public class NameMatch {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String firstName = [Link]();
String lastName = [Link]();
if([Link]("Kushagra") && [Link]("Agrawal")) {
[Link]("Matched");
} else {
[Link]("Not Matched");
Test Cases:
Test Case No. First Name Last Name Expected Output
TC1 Kushagra Agrawal Matched
TC2 Kushagra Sharma Not Matched
TC3 Ram Kumar Not Matched
TC4 kushagra agrawal Not Matched
Coverage Type Status
Statement Coverage 100%
Branch Coverage 100%
Both matching and non-matching cases are tested, so full coverage is achieved.
Experiment 1(c)
Aim:To write a Java program that takes coefficients of a quadratic equation and finds its roots, and
design test cases.
Progeam:
import [Link];
public class Quadratic {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
double a = [Link]();
double b = [Link]();
double c = [Link]();
double d = b*b - 4*a*c;
if(d > 0) {
double r1 = (-b + [Link](d)) / (2*a);
double r2 = (-b - [Link](d)) / (2*a);
[Link]("Roots are: " + r1 + " and " + r2);
else if(d == 0) {
double r = -b / (2*a);
[Link]("Equal roots: " + r);
else {
[Link]("Imaginary roots");
} }
}
Test Cases:
Test Case No. a b c Discriminant (d) Expected Output
TC1 1 -3 2 >0 Roots: 1 and 2
TC2 1 2 1 =0 Equal root: -1
TC3 1 1 1 <0 Imaginary roots
TC4 0 2 1 Invalid case Error / Not quadratic
Coverage:
Statement Coverage: All statements executed ✔
Branch Coverage:
o d>0✔
o d == 0 ✔
o d<0
Coverage Type Status
Statement Coverage 100%
Branch Coverage 100%
All three cases of discriminant (positive, zero, negative) are tested, hence full coverage is achieved.
Experiment 1(d)
Aim:
Write a program that reads a commercial website URL from the input.
The URL should start with “www” and end with “.com”.
The program should retrieve the name of the website and output it.
Example:
If the input is [Link], the output should be yahoo.
Also, design test cases and find the coverage of the program using JaButi Tool.
Program:
import [Link];
public class URLExtract {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String url = [Link]();
if([Link]("www.") && [Link](".com")) {
String name = [Link](4, [Link]() - 4);
[Link]("Site Name: " + name);
} else {
[Link]("Invalid URL");
Test Cases:
Test Case No. Input URL Expected Output
TC1 [Link] yahoo
TC2 [Link] google
TC3 [Link] Invalid URL
TC4 [Link] Invalid URL
TC5 [Link] abc
Coverage:
Statement Coverage: All statements executed ✔
Branch Coverage:
o Valid URL condition ✔
o Invalid URL condition
Coverage Type Status
Statement Coverage 100%
Branch Coverage 100%
The program was executed using JaBUTi tool to analyze statement and branch coverage. The results show that
all statements and conditions are covered.
Experiment 1(e)
Aim:
Write a program for a calculator that performs basic arithmetic operations (+, −, *, /).
Also, design test cases, find the coverage, and draw the Def-Use graph of the program using JaButi tool.
Program:
import [Link];
public class Calculator {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int a = [Link]();
int b = [Link]();
char op = [Link]().charAt(0);
switch(op) {
case '+':
[Link]("Result = " + (a + b));
break;
case '-':
[Link]("Result = " + (a - b));
break;
case '*':
[Link]("Result = " + (a * b));
break;
case '/':
if(b != 0)
[Link]("Result = " + (a / b));
else
[Link]("Divide by zero error");
break;
default:
[Link]("Invalid Operator");
TestCases:
Test Case No. a b Operator Expected Output
TC1 53 + 8
TC2 53 - 2
TC3 42 * 8
TC4 62 / 3
TC5 50 / Divide by zero error
TC6 53 % Invalid Operator
Coverage:
Statement Coverage: All statements executed ✔
Branch Coverage:
o All operators (+, -, *, /) ✔
o Divide by zero condition ✔
o Default case ✔
The program was tested using JaBUTi tool to verify statement coverage, branch coverage, and
def-use paths.
Experiment 1(f)
Aim:
Write a program that reads two words representing passwords from the Java console and outputs the number of
characters in the smaller word.
For example, if the words are "open" and "same", then the output should be 4.
Also test this program using JaButi.
Program:
import [Link];
public class PasswordLength {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String word1 = [Link]();
String word2 = [Link]();
int len1 = [Link]();
int len2 = [Link]();
if(len1 < len2) {
[Link]("Length = " + len1);
} else {
[Link]("Length = " + len2);
Test Cases:
Test Case No. Word1 Word2 Expected Output
TC1 open same 4
TC2 hello hi 2
TC3 abc xyz 3
TC4 a abcd 1
Coverage:
Statement Coverage: All statements executed ✔
Branch Coverage:
o len1 < len2 ✔
o len1 ≥ len2 ✔
Coverage Type Status
Statement Coverage 100%
Branch Coverage 100%
The program was tested using JaBUTi tool to verify statement and branch coverage.
Experiment 2
Aim:Analyse the performance of following websites using JMeter:
[Link] (Shopping)
[Link] (Shopping)
[Link] (Ticket booking site)
[Link] (Train searching)
Steps (Procedure):
1. Open Apache JMeter
2. Add Thread Group
3. Set:
o Number of Users (Threads): 10
o Ramp-Up Period: 5
o Loop Count: 1
4. Add HTTP Request Sampler
5. Enter website URL:
o [Link]
o [Link]
o [Link]
o [Link]
6. Add Listener → View Results Tree / Summary Report
7. Run the test
8. Note results like:
o Response Time
o Throughput
o Status (Success/Fail)
Test Case:
Test Case No. Website Users Expected Result
TC1 Amazon 10 Fast response
TC2 Flipkart 10 Moderate response
TC3 IRCTC 10 May be slow
TC4 Erial 10 Fast response
Sample Result Table:
Website Avg Response Time Throughput Status
Amazon 200 ms High Success
Flipkart 300 ms Medium Success
IRCTC 800 ms Low Success
Erial 250 ms Medium Success
Conclusion:
Amazon shows best performance with lowest response time, while IRCTC is comparatively slower under load.
Experiment 3
Aim:
Calculate the mutation score of programs given in Experiment 1(a) to 1(f) using Jumble Tool.
Concept : Mutation testing is used to check the quality of test cases by introducing small changes
(mutants) in the program.
[Link] Program
Mutant Original Mutated Status
M1 r*r r+r Killed
M2 [Link] [Link]*r Killed
M3 r>=0 r>0 Alive
Total = 3, Killed = 2
Score = 66.6%
[Link] Matching
Mutant Original Mutated Status
M1 equals != Killed
M2 && || Killed
M3 "Kushagra" "kushagra" Alive
Total = 3, Killed = 2
👉 Score = 66.6%
[Link] Equation:
Mutant Original Mutated Status
M1 b*b b+b Killed
M2 4ac 2ac Killed
M3 d>0 d>=0 Alive
M4 d==0 d!=0 Killed
👉 Total = 4, Killed = 3
👉 Score = 75%
[Link] Program:
Mutant Original Mutated Status
M1 startsWith endsWith Killed
M2 .com .org Killed
M3 substring(4,...) substring(3,...) Alive
👉 Total = 3, Killed = 2
👉 Score = 66.6%
[Link]:
Mutant Original Mutated Status
M1 + - Killed
M2 * / Killed
M3 b!=0 b==0 Killed
M4 default removed Alive
Total = 4, Killed = 3
👉 Score = 75%
[Link] Length:
Mutant Original Mutated Status
M1 len1<len2 len1>len2 Killed
M2 len2 len1 Killed
M3 < <= Alive
👉 Total = 3, Killed = 2
👉 Score = 66.6%
Final Overall Mutation Score:
Total Mutants = 20
Killed Mutants = 14
Result:
Overall mutation score of the programs is 70%.Jumble tool is used to generate mutants and evaluate the
effectiveness of test cases.
Experiment 4
Aim:
Calculate the coverage analysis of programs given in Experiment 1(a) to 1(f) using EclEmma free open-source
tool.
Procedure:
1. Open Eclipse IDE
2. Install EclEmma Plugin
3. Import Java programs (a–f)
4. Right click on program → Coverage As → Java Application
5. Observe coverage results:
o Green → Covered code
o Red → Not covered
Summary Table:
Program Statement Coverage Branch Coverage
(a)circle 100% 100%
(b)name matching 100% 100%
(c)quadratic 100% 100%
(d)URL 100% 100%
(e)Calculator 100% 100%
(f)Password Length 100% 100%
Result:
All programs achieved 100% statement and branch coverage using EclEmma tool.