Software Testing Lab File
Software Testing Lab File
S. EXPERIMENT
no
.
1. Validation of a program to find the minimum and maximum element out of a given list.
2. Select a program with at least three inputs and design the test cases for the same using the following techniques:
i) Equivalence class
4. Write a program to display percentage of different coverage (i.e. statement coverage, path coverage, condition coverage,
function coverage) achieved for a given program during the execution of various test cases. (Try to develop a Tool to
display different coverage for any given Program)
5. Write a program for regression testing by assigning priorities to different test cases.
6. Write a program to perform data flow testing for a given program (Try to develop a tool to perform data flow testing over any
given Program in terms of the parameters discussed in class)
7. Conduct a Survey of (At least Five) different Testing Tools available. Prepare a Presentation of their advantages and
disadvantages
8. Conduct at least four experiments to explore the strength of any of the following testing tools for automated testing
a. Rational robo
b. NUnit
c. JUNIT
Here are some test cases that can be used to validate a program that finds the minimum and
maximum element out of a given list in C++:
1. Test case with an empty
list: ● Input: []
● Output: (min: 0, max: 0)
2. Test case with a list of length
1: ● Input: [5]
● Output: (min: 5, max: 5)
3. Test case with a list of length
2: ● Input: [5, 10]
● Output: (min: 5, max: 10)
4. Test case with a list of length
3: ● Input: [5, 10, -5]
● Output: (min: -5, max: 10)
5. Test case with a list of length greater than
3: ● Input: [5, 10, -5, 20, -30, 0, 15]
● Output: (min: -30, max: 20)
6. Test case with a list containing all positive
numbers: ● Input: [5, 10, 20, 30, 40, 50]
● Output: (min: 5, max: 50)
7. Test case with a list containing all negative
numbers: ● Input: [-5, -10, -20, -30, -40, -50]
● Output: (min: -50, max: -5)
8. Test case with a list containing both positive and negative
numbers: ● Input: [-5, -10, 20, -30, 40, 50]
● Output: (min: -30, max: 50)
Exp 2 : 2. Select a program with at least three inputs and design the test cases for the same using
the following techniques:
i) Equivalence class
ii) Decision table testing
iii) Boundary value testing
iv) Cause effect graph
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double a, b, c;
cout << "Enter the sides of the triangle: ";
cin >> a >> b >> c;
cout << "Area of the triangle: " << calculate_area(a, b, c) <<
endl; return 0; }
This program takes in three inputs - the sides of a triangle - and calculates the area of the triangle
using Heron's formula.
a b c area
3 4 5 6
3 4 10 0
0 4 5 0
3 -4 5 0
Boundary value testing:
● Test case 1: a = 0, b = 0, c = 0 (minimum value for all sides)
● Test case 2: a = DBL_MAX, b = DBL_MAX, c = DBL_MAX (maximum value for all sides)
● Test case 3: a = DBL_MAX, b = DBL_MAX, c = 1 (maximum value for two sides and minimum value
for one side)
● Test case 1: a = 3, b = 4, c = 5
● Test case 2: a = 5, b = 4, c = 3
● Test case 3: a = 5, b = 3, c = 4
● Test case 4: a = 4, b = 5, c = 3
● Test case 5: a = 4, b = 3, c = 5
● Test case 6: a = 3, b = 5, c = 4
● Test case 7: a = 0, b = 4, c = 5
● Test case 8: a = 3, b = -4, c = 5
● Test case 9: a = DBL_MAX, b = DBL_MAX, c = DBL_MAX
● Test case 10: a = DBL_MAX, b = DBL_MAX, c = 1
Exp 3: Write a program to find cyclomatic complexity of a program.
#include <iostream>
#include <string>
using namespace std;
int main() {
#include <iostream>
#include <unordered_set>
/ Set the number of statements, paths, conditions, and functions that were executed.
int executedStatements = 90;
int executedPaths = 40;
int executedConditions = 60;
int executedFunctions = 20;
return 0;
}
Exp 5 : Write a program for regression testing by assigning priorities to different test cases.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
/ This function compares two test cases based on their priority.. bool
compareTestCases(const TestCase& a, const TestCase& b) {
return a.priority < b.priority;
}
int main() {
/ Create a vector of test cases.
vector<TestCase> testCases =
{ {"Test case 1", 2},
{"Test case 2", 3},
{"Test case 3", 1},
{"Test case 4", 2},
{"Test case 5", 3},
};
return 0;
}
Exp 6 : Write a program to perform data flow testing for a given program (Try to develop a tool to
perform data flow testing over any given Program in terms of the parameters discussed in class)
#include <iostream>
#include <string>
#include <vector>
#include <unordered_set>
return variables;
}
int main() {
/ Read the lines of code
vector<Line> lines;
cout << "Enter the lines of code: " << endl;
string line;
int line_number = 1;
while (getline(cin, line)) {
lines.push_back({ line_number,
line }); line_number++;
}
unordered_set<string> variables;
/ Iterate through the lines of code and add any variables used in the
code for (const Line& line : lines) {
for (const Variable& variable : get_variables(line.code))
{ variables.insert(variable.name);
}
}
return 0;
}
Exp 7: Conduct a Survey of (At least Five) different Testing Tools available. Prepare a Presentation
of their advantages and disadvantages
1. JUnit: JUnit is a popular open-source testing tool for Java. It allows developers to write and run
repeatable tests. One advantage of JUnit is its simplicity, as it has a small API and is easy to use.
Another advantage is its integration with various build and continuous integration tools, such as
Maven and Jenkins. However, JUnit can only be used for testing Java programs, and does not
support testing of GUI applications.
2. TestNG: TestNG is another popular testing tool for Java, similar to JUnit. It offers additional features
such as support for parallel testing and the ability to specify dependencies between test methods.
TestNG also allows for the use of custom annotations and test groups. However, TestNG can be
more complex to use than JUnit, and may require more setup and configuration.
3. Selenium: Selenium is a browser automation tool that can be used for testing web applications. It
supports a variety of programming languages, including Java, Python, and C#. One advantage of
Selenium is its ability to run tests on multiple browsers and operating systems. It also has good
integration with various testing frameworks and continuous integration tools. However, Selenium can
be slow to execute tests, and may require additional setup and configuration to run tests in parallel.
4. Appium: Appium is a mobile application testing tool that allows developers to test native, hybrid, and
web apps on various mobile platforms, including iOS and Android. It supports a variety of
programming languages and has good integration with continuous integration tools. One advantage of
Appium is its ability to test apps on real devices, which can be more accurate than emulators.
However, it can be challenging to set up and configure, and may require additional setup for testing on
different mobile platforms.
5. Postman: Postman is a tool for testing APIs, allowing developers to send HTTP requests and validate
the responses. It has a user-friendly interface and supports various types of requests, such as GET,
POST, and PUT. It also has features for creating and sharing collections of requests and running
automated tests. One advantage of Postman is its easy setup and use, as it is a standalone
application that does not require any additional configuration. However, it may not be suitable for
testing more complex APIs or for integration with continuous integration tools.
Exp 8: Conduct at least four experiments to explore the strength of any of the following testing tools
for automated testing
a. Rational robo
b. NUnit
c. JUNIT
1. Test execution time: One experiment that could be conducted is to measure the execution time of a
set of test cases using JUnit. This could help to determine how efficiently JUnit is able to run tests.
2. Test coverage: Another experiment could be to measure the test coverage achieved by JUnit for a
given codebase. This could help to determine how effective JUnit is at finding defects in the code.
3. Integration with build and continuous integration tools: Another experiment could be to evaluate the
integration of JUnit with various build and continuous integration tools, such as Maven or Jenkins.
This could help to determine how convenient it is to use JUnit in a continuous integration workflow.
4. Ease of use: A final experiment could be to evaluate the ease of use of JUnit, for example by
comparing the learning curve for the tool or the number of lines of code required to write and run
tests. This could help to determine how user-friendly JUnit is.
Exp 9 : Write a program to perform mutation testing of a given program.
#include <iostream>
#include <vector>
/ The function to be
tested int add(int a, int b) {
return a + b;
}
int main() {
// Test cases
vector< pair<int, int>> test_cases = {
{1, 2},
{-1, -2},
{0, 0},
{100, 200}
};
// Mutation operators
vector< function<int(int)>> mutations = {
[](int x) { return x + 1; }, // Replace + with ++
[](int x) { return x - 1; }, // Replace + with --
[](int x) { return -x; } // Replace + with -
};
#include <iostream>
#include <vector>
/ The function to be
tested int add(int a, int b) {
// int c = a + b;
// int d = a - b;
/ / int e = a * b;
// int f = a / b;
// return c + d + e + f;
// }
// int main() {
// // Test cases
/ / vector< pair<int, int>> test_cases = {
/ / {1, 2},
/ / {-1, -2},
/ / {0, 0},
/ / {100, 200},
/ / {3, 4}
/ / };
// // Slices
/ / vector< vector<int>> slices = {
{1, 2}, // a + b
{3, 4}, // a - b
{5, 6}, // a * b
{7, 8} // a / b
/ / };
/ / // Initialize the coverage matrix
/ vector< vector<bool>> coverage(test_cases.size(), vector<bool>(slices.size(), false));
/
// // Loop over test cases
// for (size_t i = 0; i < test_cases.size(); i++) {
/ / const auto& [a, b] = test_cases[i];
/ int result = add(a, b);
/
// Loop over slices
for (size_t j = 0; j < slices.size(); j++) {
const auto& [start, end] = slices[j];