0% found this document useful (0 votes)
15 views46 pages

STT Labsss

The document is a lab manual for Software Testing Technologies at Punjab Tianjin University of Technology, authored by Saad Khalid. It outlines various labs focusing on programming tasks in C#, including calculator testing, decision-making structures, loops, arrays, functions, database connections, and unit testing. Additionally, it covers both white box and black box testing methodologies for different applications developed throughout the course.

Uploaded by

faisalmlik9211
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views46 pages

STT Labsss

The document is a lab manual for Software Testing Technologies at Punjab Tianjin University of Technology, authored by Saad Khalid. It outlines various labs focusing on programming tasks in C#, including calculator testing, decision-making structures, loops, arrays, functions, database connections, and unit testing. Additionally, it covers both white box and black box testing methodologies for different applications developed throughout the course.

Uploaded by

faisalmlik9211
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

PUNJAB TIANJIN UNIVERSITY OF TECHNOLOGY

Software Testing technologies

Lab Manuals

Subject Software Testing Technologies

Submitted by Saad Khalid 23-SET-036

Semester Spring 2025 (4th Semester)

Submitted to Sir Umar Hayat

Department of Software Engineering Technology


LAB # 01
OBJECTIVE: To test and debug the calculator program in Visual Studio, set breakpoints at key
lines and test it and sow output.

1. Make the program in C# to make Calculator in visual Studio.

2. After making the program in C# then I test it in the visual studio line by line by using
break point in C#.
3. After White box testing by using break point in visual studio show Output. In this all
operation perform good.

Division Operation:

Modulus Operation:

Addition Operation:

Minus Operation:
Lab # 02: Decision-Making Structures in C#

Objective:
Learn how to use decision-making structures (if, if-else, switch) to write programs that make
choices based on conditions.
 Implement white box testing
 Implement black box testing

Task 1: User Validation Program.

White Box Testing and Black Box Testing:

OUTPUT:
Task 2: Student Grade Book
Create a program that accepts student marks and assigns a grade based on the score.

White Box Testing and Black Box Testing:

OUTPUT:

Task 3: Month Name Program


Create a program that takes a number between `1-12` and prints the corresponding month name.

White Box Testing and Black Box Testing:

OUTPUT:
Lab # 03: Loops in C#

Objective:
Understand and implement for, while, and do-while loops to solve repetitive tasks efficiently.

Task 1: Multiplication Table (For Loop)


 Description: User enters a number, and the program prints its multiplication table from 1
to 10.

 Loop Used: for loop

 Testing: Breakpoint added before the loop; verified each iteration and output.
Task 2: Sum of Even Numbers (1 to 50)
 Description: Program calculates the sum of all even numbers between 1 and 50.

 Loop Used: for loop with if (i % 2 == 0) condition.

 Testing: Breakpoint added inside the loop to watch how the sum variable updates.
Lab # 04: Arrays in C#

Objective:
 Learn how to declare, initialize, and manipulate arrays.
 Learn single dimension array
 Learn understand multidimensional array
Task 1: Single-Dimensional Array
1. Create an array that stores 5 integers.

2. Input: The user is prompted to enter 5 integers.

3. Output: The array is displayed in reverse order. We use a for loop to traverse the array
backward and print each number.
Task 2: Multidimensional Array (Student Info)
1. Create a 2D array (string[,] studentInfo) to store student information.

o Each row will represent a student.

o Columns will store the student’s name, age, and grade.

2. Display: The program will print the student data in a tabular format.
Lab # 05: Function, Classes and MSUnit testing
Objective:
 Understand how to define and call functions and classes to make the code modular and
reusable.
 Learn how to use exception handling
 Learn how to implement MS Unit testing

Tasks:

Bank Account:
Create a BankAccount Class with Debit and Credit functions:
Create Bank Account Tests class to implement unit testing using MSUnit:

Run debug and test application:


Lab # 06

Objective:
 Create Relational Database In Visual Studio and Connect with the business Logic.

1. Right Click on the Create Project lab 6_8 and add database in it name as mydb.mdf.

2. Open the mydb and right Click on the table and create table like Users, Categories, products.

//Saad Khalid Khan


 User Table SQL Code
CREATE TABLE [dbo].[users] ( //Saad Khalid Khan
[id] INT NOT NULL IDENTITY,
[email] NVARCHAR (255)Unique NOT NULL,
[First_name] NVARCHAR (50) NOT NULL,
[Last_Name] NVARCHAR (50) NOT NULL,
[address] NVARCHAR (50) NULL,
[sec_question] NVARCHAR (50) NOT NULL,
[sec_answer] NVARCHAR (50) NOT NULL,
[password] NVARCHAR (50) NOT NULL,
[user_type] NVARCHAR (50) NOT NULL,
[status] NVARCHAR (50) NOT NULL,
[mobile] NCHAR(10) NOT NULL,
PRIMARY KEY CLUSTERED ([id] ASC)
);
 Categories Table SQL Code
CREATE TABLE [dbo].categories
( // Saad Khalid Khan
[cart_id] INT NOT NULL PRIMARY KEY IDENTITY,
[title] NVARCHAR(50) NULL,
[description] NVARCHAR(50) NULL,
[photo] NVARCHAR(MAX) NULL
)
 Product Table SQL Code
CREATE TABLE [dbo].products
( // Saad Khalid Khan
[product_id] INT NOT NULL PRIMARY KEY IDENTITY,
[cart_id] INT NULL,
[product_title] NVARCHAR(50) NULL,
[description] NVARCHAR(50) NULL,
[company] NVARCHAR(50) NULL,
[old_price] DECIMAL NULL,
[new_price] DECIMAL NULL,
[man_date] DATE NULL,
[exp_date] DATE NULL,
[photo] NVARCHAR(50) NULL,
[status] NVARCHAR(50) NULL)
LAB # 07 & 08
Objective: Understand the Connection String and Create the User Registration with database Connection.

Create a project name as lab 6_8 right click on in and add class named as DAO login in visual Studio.

1. Explain DAO LOGIN CLASS (Database Interaction Class).

Class Declaration:

This defines a class login_DAO which is responsible for performing operations like signup, login,
and password updates.
The connectionString variable stores the connection details needed to connect to the SQL Server
database (LocalDB in this case).
Signup Method:

Purpose: This method registers a new user in the database.


 It opens a connection to the database, prepares an SQL INSERT query to add a new user’s
details, and executes the query using the SqlCommand object.
 It uses parameters (e.g., @email, @First_name) to safely insert values and prevent SQL
injection (attacks that manipulate the SQL query).

Login Validation Method:


 Purpose: This method checks if the provided email and password match a record in the
database.
 It uses a SELECT query to find the user with the matching email and password.
 SqlDataReader reads the result from the query. If any rows are returned, it means the
email and password are correct.

Change password:

Purpose: This method checks if the old password is correct using isValid. If valid, it calls
updatePassword to update the password.

Update Password:

 Purpose: This method updates the password for a given email.


 It uses an UPDATE query to change the password in the users table for the specified email.
Forget password:

 Purpose: This method resets the password for a user by verifying their security question and
answer.
 It first checks if the email, security question, and answer match any user in the database.
 If they match, it calls updatePassword to reset the password.

2. Explain the Program.cs (Main Program)

Menu Loop:
 This while loop keeps running until the user chooses to exit.
 It shows a menu with options for signup, login, changing passwords, and more.

Signup Option:

 When the user selects "Signup", it prompts them to enter details like email, name,
password, etc.
 It then calls the Signup method from the login_DAO class to add the user to the database.

Login Option:

 When the user selects "Login", they are asked for an email and password.
 The isValid method checks whether the credentials are correct.
Change Password Option:

 The user provides their email, old password, and new password.
 The changePassword method checks if the old password is correct, and then it updates
the password.

Forgot Password Option:

 This option helps the user reset their password by verifying their security question and
answer.
Exit Option:

 If the user selects "Exit", the program will close.

3. Run and show the on the black box Output with database.
Signup Process:
IN BLACK BOX:

Login Process:

In Black Box:
Change Password:

Before Password: “Saad Khalid 36”

In Black Box:

Forget Password:

Previous password i forget: “Saad Khan 36”

In Black Box:
Password:

Define Test class and test methods:


Lab# 09 & 10:
Objective:
To understand and implement different types of collections in C#, including Arrays, Lists,
Dictionaries, Queues, and Stacks. This lab helps practice handling and manipulating data using
these collections.

Task 1: Arrays – Fixed Size Collection

What We Did:

 Created an integer array of size 5.

 Took input from the user.

 Displayed the array values.

 Sorted the array.

 Found the maximum and minimum values


Output:

Task 2: Lists – Dynamic Collection

What We Did:

 Created a List<string> of names.


 Displayed the list.
 Removed a name.
 Checked if a name exists.
 Sorted the list alphabetically.
Output:

Task 3: Dictionaries – Key-Value Collection

What We Did:
 Created a dictionary with student ID (int) as key and name (string) as value.

 Displayed all entries.


 Removed a student by ID.
 Checked if a student ID exists.
Output:

Task 4: Queues – FIFO (First In, First Out)

What We Did:

 Created a queue of customer names.


 Displayed all customers.
 Removed the first customer (processed).
 Checked if queue is empty after processing.
Output:

Task 5: Stacks – LIFO (Last In, First Out)

What We Did:

 Created a stack and pushed numbers onto it.


 Displayed the stack.
 Removed (popped) the top element.
 Peeked at the top without removing.
 Checked if the stack is empty.
Output:
Lab # 11:
Task: unit test of each functionality

UsingMicrosoft.VisualStudio.TestTools.Un

itTesting; using

System.Collections.Generic;

namespace ProductApp.Tests
{
[TestClass] public

class ProductServiceTests

{
private ProductService _service;

[TestInitialize]

public void

Setup()

{
string conn = "Data Source=localhost;Initial Catalog=ProductDB;Integrated

Security=True;"; _service = new ProductService(conn);

[TestMethod]

public void

TestCreateProduct()

{
bool result = _service.CreateProduct("TestWatch", "test.jpg", 99.99m, 5);
Assert.IsTrue(result, "Product should be created successfully.");
}

[TestMethod]

public void

TestReadProducts()

{
List<string> products = _service.ReadProducts();
Assert.IsTrue(products.Count > 0, "There should be products in the list.");
}

[TestMethod]

public void

TestUpdateProduct()

{
bool result = _service.UpdateProduct(1, "UpdatedName", 199.99m, 10);
Assert.IsTrue(result, "Product should be updated.");
}
[TestMethod]

public void

TestDeleteProduct()

{
bool result = _service.DeleteProduct(1); // Use a valid ID
Assert.IsTrue(result, "Product should be deleted.");
}
}
}
Lab # 12:

Task: module test of whole application


usingMicrosoft.VisualStudio.TestTools.Uni

tTesting; using System.Linq;

namespace ProductApp.Tests
{
[TestClass] public

class ProductModuleTests

{
private ProductService

_service; private int

_testProductId;

public void Init()

{
string conn = "Data Source=localhost;Initial Catalog=ProductDB;Integrated

Security=True;";

_service = new ProductService(conn);

}
[TestMethod]

public void

TestFullCRUDModule()

{
// 1. Create

bool created = _service.CreateProduct("ModuleTest",

"module.jpg", 50.00m, 2);

Assert.IsTrue(created, " Product creation failed.");

// 2. Read and Find Created Product

var all = _service.ReadAllProducts();

var createdProduct = all.FirstOrDefault(p => p.ProductName ==

"ModuleTest");
Assert.IsNotNull(createdProduct, "Created product not found.");
_testProductId = createdProduct.ProductID;

// 3. Update

bool updated = _service.UpdateProduct(_testProductId,

"ModuleUpdated", 60.00m, 3);

Assert.IsTrue(updated, " Product update failed.");

// 4. Confirm Update

var updatedProduct = _service.ReadAllProducts().FirstOrDefault(p => p.ProductID

== _testProductId);

Assert.AreEqual("ModuleUpdated", updatedProduct.ProductName, " Product name not


updated.");

// 5. Delete

bool deleted =

_service.DeleteProduct(_testProductId);

Assert.IsTrue(deleted, " Product deletion

failed.");

// 6. Confirm Deletion

var deletedProduct = _service.ReadAllProducts().FirstOrDefault(p => p.ProductID

== _testProductId);

Assert.IsNull(deletedProduct, " Deleted product still exists.");


}
}
}
Lab # 13:

Task: White box testing of whole application

1. Introduction
This report outlines the white box testing process for the ProductDB CRUD Console Application developed
in C#. The objective of white box testing is to verify the internal logic and structure of each module and
ensure full statement and branch coverage.

2. Testing Techniques Used


- Statement Coverage
- Branch Coverage
- Path Coverage
- Exception Handling Coverage

3. Test Scenarios by Function


Function Test Case Input Expected Output
Description
CreateProduct Valid input ProductName, Photo, Product added
Price=50, successfully
Quantity=10
CreateProduct Empty name Name='', Photo, Invalid input error
Price=50,
Quantity=10
CreateProduct Invalid price Name='Test', Photo, Invalid input error
Price='abc',
Quantity=10
CreateProduct Database connection Simulate DB failure Exception caught and
failure error displayed
ReadProducts Products exist Database with Product list displayed
products
ReadProducts DB failure Simulate DB error Exception caught and
error displayed
UpdateProduct Valid ID ID=1, Product updated
Name='Updated',
Price=99
UpdateProduct Nonexistent ID ID=999, Product not found
Name='NoChange'
UpdateProduct DB error Simulate error Exception caught
DeleteProduct Valid ID ID=1 Product deleted
DeleteProduct Invalid ID ID=999 Product not found
DeleteProduct DB failure Simulate error Exception caught
4. Tools Used
- Visual Studio
- MSTest Framework
- Visual Studio Code Coverage Analyzer

5. Summary Coverage Table


Function Technique Tools Status
CreateProduct Branch, Statement, MSTest, Code Tested
Exception Handling Coverage
ReadProducts Statement, Exception MSTest Tested
Path
UpdateProduct Branch, DB MSTest Tested
Validation,
Exception
DeleteProduct Path, DB Logic MSTest Tested
Lab # 14:
Task: Black box testing of whole application

1. Introduction
This report outlines the black box testing process for the ProductDB CRUD Console Application. Black
box testing focuses on testing the application's functionality without knowledge of its internal code
structure. The aim is to validate that the system behaves as expected for different input conditions.

2. Testing Techniques Used -


Equivalence Partitioning
- Boundary Value Analysis
- Error Guessing
- Positive and Negative Testing

3. Test Scenarios and Expected Results


Functionality Test Case Input Data Expected Result
Create Product Valid product entry ProductName='Phone' Product created
, Photo='img.jpg', successfully
Price=499.99,
Quantity=10
Create Product Empty product name ProductName='', Error: Name is
Photo='img.jpg', required
Price=499.99,
Quantity=10
Create Product Negative price ProductName='Phone' Error: Invalid price
, Photo='img.jpg',
Price=-10,
Quantity=10
Create Product Missing photo ProductName='Phone' Error: Photo is
, Photo='', required
Price=499.99,
Quantity=10
Read Products Display all products N/A All products listed
Read Products Empty database No products in table No products
available
Update Product Valid update ProductID=1, New Product updated
Name='Tablet' successfully
Update Product Nonexistent ProductID=999 Error: Product not
ProductID found
Delete Product Valid deletion ProductID=1 Product deleted
successfully
Delete Product Invalid ProductID ProductID='abc' Error: Invalid
Product ID
Delete Product Nonexistent ProductID=999 Error: Product not
ProductID found

4. Conclusion
Black box testing verified that the application correctly handles valid and invalid inputs. Each feature
(Create, Read, Update, Delete) was tested for positive and negative scenarios. The application met the
functional requirements under all tested conditions.
Lab # 15 & 16:
Product CRUD operation using MS SQL and C#
Task 1: Setting Up the Database
1. Database:

CREATE DATABASE ProductDB;


GO
USE ProductDB;
-- 2. Create Products Table
CREATE TABLE Products (
ProductID INT IDENTITY(1,1) PRIMARY KEY,
ProductName NVARCHAR(100) NOT NULL,
Photo NVARCHAR(100) NOT NULL,
Price DECIMAL(10, 2) NOT NULL,
Quantity INT NOT NULL
);
-- 3. Insert Sample Records
INSERT INTO Products (ProductName, Photo, Price, Quantity) VALUES
('Watch A', 'watchA.jpg', 199.99, 10),
('Watch B', 'watchB.jpg', 249.50, 5),
('Watch C', 'watchC.jpg', 149.00, 20);

Task 2: Creating the C# Application:


Task 3: Implementing CRUD Operations:
Task 4: Enhancements and Validation:
using System; using

System.Data.SqlClie

nt; namespace

ProductApp

{
class Program
{
static string connectionString = "Data Source=localhost;Initial

Catalog=ProductDB;Integrated Security=True;"; static void Main(string[] args)

while (true)

{
Console.Clear();
Console.WriteLine("=== ProductDB CRUD Application ===");
Console.WriteLine("1. Create Product");
Console.WriteLine("2. Read All Products");
Console.WriteLine("3. Update Product");
Console.WriteLine("4. Delete Product");
Console.WriteLine("5. Exit");

Console.Write("Select an option: ");

switch (Console.ReadLine())
{

case "1":

CreateProduct();

break;

case "2":

ReadProducts();

break;

case "3":

UpdateProduct();

break;

case "4":

DeleteProduct();

break;

case "5":

return;

default:

Console.WriteLine("Invalid

choice!");

break;

Console.WriteLine("\nPress Enter to continue...");


Console.ReadLine();
}
}
static void CreateProduct()
{
Console.Write("Enter Product

Name: ");

string name = Console.ReadLine();

Console.Write("Enter Photo Filename (e.g., image.jpg): ");


string photo = Console.ReadLine();

Console.Write("Enter Price: ");

bool priceValid = decimal.TryParse(Console.ReadLine(), out

decimal price);

Console.Write("Enter Quantity: ");

bool qtyValid = int.TryParse(Console.ReadLine(), out int

quantity);

if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(photo) || !priceValid ||


!qtyValid)
{
Console.WriteLine("Invalid

input."); return;

string query = "INSERT INTO Products (ProductName, Photo, Price, Quantity) VALUES

(@name, @photo, @price, @qty)";

using SqlConnection con = new SqlConnection(connectionString);

using SqlCommand cmd = new SqlCommand(query, con);

cmd.Parameters.AddWithValue("@name", name);

cmd.Parameters.AddWithValue("@photo", photo);

cmd.Parameters.AddWithValue("@price", price);
cmd.Parameters.AddWithValue("@qty", quantity);

try
{
con.Open();

cmd.ExecuteNonQuery();

Console.WriteLine(" Product added successfully.");


}
catch (Exception ex)
{

Console.WriteLine(" Error: " + ex.Message);


}
}

static void ReadProducts()


{
string query = "SELECT * FROM Products";

using SqlConnection con = new

SqlConnection(connectionString);

using SqlCommand cmd = new

SqlCommand(query,con);

try
{
con.Open();

using SqlDataReader reader =

cmd.ExecuteReader();

Console.WriteLine("\n--- Product List ---");

while (reader.Read())

{
Console.WriteLine($"ID: {reader["ProductID"]}, Name: {reader["ProductName"]}, Price:
{reader["Price"]}, Qty: {reader["Quantity"]}, Photo: {reader["Photo"]}");
}
}
catch (Exception ex)
{

Console.WriteLine(" Error: " + ex.Message);


}
}

static void UpdateProduct()


{
Console.Write("Enter Product ID

to update: "); if

(!int.TryParse(Console.ReadLine(), out int

id))

Console.WriteLine("Invalid ID.");

return;

Console.Write("Enter New Name: ");

string name = Console.ReadLine();

Console.Write("Enter New Price: ");

bool priceValid = decimal.TryParse(Console.ReadLine(), out

decimal price);

Console.Write("Enter New Quantity: ");

bool qtyValid = int.TryParse(Console.ReadLine(), out int

quantity);

if (string.IsNullOrWhiteSpace(name) || !priceValid || !qtyValid)


{
Console.WriteLine("Invalid

input."); return;

string query = "UPDATE Products SET ProductName = @name, Price = @price, Quantity =
@qty WHERE ProductID = @id";
using SqlConnection con = new
SqlConnection(connectionString);
using SqlCommand cmd = new

SqlCommand(query, con);
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@price", price);
cmd.Parameters.AddWithValue("@qty", quantity);
cmd.Parameters.AddWithValue("@id", id);

try
{
con.Open();

int rows =

cmd.ExecuteNonQuery();

Console.WriteLine(rows > 0 ? Product updated." : " Product not found.");


}
catch (Exception ex)
{

Console.WriteLine(" Error: " + ex.Message);


}
}

static void DeleteProduct()


{
Console.Write("Enter Product ID

to delete: "); if

(!int.TryParse(Console.ReadLine(), out int

id))

Console.WriteLine("Invalid ID.");

return;

string query = "DELETE FROM Products WHERE

ProductID = @id";
using SqlConnection con = new

SqlConnection(connectionString);

using SqlCommand cmd = new SqlCommand(query, con);

cmd.Parameters.AddWithValue("@id", id);

try
{
con.Open();

int rows =

cmd.ExecuteNonQuery();

Console.WriteLine(rows > 0 ? " Product deleted." : " Product not found.");


}
catch (Exception ex)
{

Console.WriteLine(" Error: " + ex.Message);


}
}
}
}

You might also like