SE 9th

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 20

Terna Engineering College

Computer Engineering Department


Program: Sem V

Course: Software Engineering

PART A

Experiment No.09

A.1 Aim:

Perform white box (Basic Path Testing) or black box testing on any one function
developed (code) of selected mini project and develop the test cases for same.

A.2 Prerequisite:
Knowledge about software testing and types of testing.

A.3 Outcome:
After successful completion of this experiment students will be able to differentiate
between white and black box testing and able to perform white box testing.

A.4 Theory:

Software Testing
Software testing is a method to check whether the actual software product matches expected
requirements and to ensure that software product is Defect free. It involves execution of
software/system components using manual or automated tools to evaluate one or more
properties of interest. The purpose of software testing is to identify errors, gaps or missing
requirements in contrast to actual requirements.

Testing in Software Engineering


As per ANSI/IEEE 1059, Testing in Software Engineering is a process of evaluating a
software product to find whether the current software product meets the required
conditions or not. The testing process involves evaluating the features of the software
product for requirements in terms of any missing requirements, bugs or errors,
security, reliability and performance.

 Software testing is defined as an activity to check whether the actual results match the
expected results and to ensure that the software system is Defect free.
 Testing is important because software bugs could be expensive or even dangerous.
 The important are reasons for using software testing are: cost-effective, security, product
quality, and customer satisfaction.
 Typically Testing is classified into three categories functional testing, non-functional
testing or performance testing, and maintenance.
 The important strategies in software engineering are: unit testing, integration testing,
system testing , validation testing (User acceptance testing).

 Types of Software Testing


Typically Testing is classified into three categories.

 Functional Testing
 Non-Functional Testing or Performance Testing
 Maintenance (Regression and Maintenance)

 Testing Strategies (levels) in Software Engineering

Here are important testing strategies in software engineering:


Unit Testing: This software testing approach is followed by the programmer to test the
unit of the program. It helps developers to know whether the individual unit of the code is
working properly or not.

Integration testing: It focuses on the construction and design of the software. You need to
see that the integrated units are working without errors or not.

System testing: In this method, your software is compiled as a whole and then tested as a
whole. This testing strategy checks the functionality, security, portability, amongst others.

User Acceptance Testing (Validation Testing):

 Functional Testing

1. What is Functional Testing?

FUNCTIONAL TESTING is a type of software testing that validates the software system
against the functional requirements/specifications. The purpose of Functional tests
is to test each function of the software application, by providing appropriate input,
verifying the output against the Functional requirements.

Functional testing mainly involves black box testing and it is not concerned about the
source code of the application. This testing checks User Interface, APIs, Database,
Security, Client/Server communication and other functionality of the Application under
Test. The testing can be done either manually or using automation.

What do you test in Functional Testing?

The prime objective of Functional testing is checking the functionalities of the software
system. It mainly concentrates on -

 Mainline functions: Testing the main functions of an application


 Basic Usability: It involves basic usability testing of the system. It checks whether a user can
freely navigate through the screens without any difficulties.
 Accessibility: Checks the accessibility of the system for the user
 Error Conditions: Usage of testing techniques to check for error conditions. It checks whether
suitable error messages are displayed.

How to do Functional Testing

 Understand the Functional Requirements


 Identify test input or test data based on requirements
 Compute the expected outcomes with selected test input values
 Execute test cases
 Compare actual and computed expected results

 Types of Functional Testing

White-Box Testing

1. Basic Path Testing

2. Control structure Testing


a. Branch Testing
b. Condition Testing
c. Data Flow Testing
d. Loop Testing

Black box testing

1. Equivalence Class Testing (Equivalence Partitioning)


2. Boundary Value Testing

UAT (User Acceptance Testing)

White-box testing:
 Knowing the internal workings of a product, test that all internal operations are
performed according to specifications and all internal components have been
exercised.
 Types of White Box Testing:

1) Basic Path Testing


2) Control Structure Testing

1) Basic Path Testing:

Introduction:

Path testing is a structural testing method that involves using the source code of a
program in order to find every possible executable path. It helps to determine all faults
lying within a piece of code. This method is designed to execute all or selected path through
a computer program.

Any software program includes multiple entry and exit points. Testing each of these
points is a challenging as well as time-consuming. In order to reduce the redundant
tests and to achieve maximum test coverage, basis path testing is used.

It is White-box testing technique proposed by Tom McCabe. Enables the test case designer to
derive a logical complexity of a procedural design(system). And then use this measure to
define basis set of execution paths developer uses this. Test cases derived to exercise the basis
set are guaranteed to execute every statement in the program at least one time during testing.

Basis Path Testing in software engineering is a White Box Testing method in which test cases are
defined based on flows or logical paths that can be taken through the program.

The objective of basis path testing:


Is to define the number of independent paths, so the number of test cases needed can be
defined explicitly to maximize test coverage.

Here we will take a simple example, to get a better idea what is basis path testing include

In the above example, we can see there are few conditional statements that is executed
depending on what condition it suffice. Here there are 3 paths or condition that needs to be
tested to get the output,

 Path 1: 1,2,3,5,6, 7
 Path 2: 1,2,4,5,6, 7
 Path 3: 1, 6, 7

Steps for Basis Path testing

The basic steps involved in basis path testing include;

 Draw a control graph (flow graph) (to determine different program paths)
 Calculate Cyclomatic complexity (metrics to determine the number of independent paths)
 Find a basis set of paths
 Generate test cases to exercise each path
 Flow Graph Notation:
 A circle in a graph represents a node, which stands for a sequence of one or more
procedural statements.
 A node containing a simple conditional expression is referred to as a predicate node.
 Each compound condition in a conditional expression containing one or more
Boolean operators (e.g., and, or) is represented by a separate predicate node.
 A predicate node has two edges leading out from it (True and False).
 An edge, or a link, is a an arrow representing flow of control in a specific direction.
 An edge must start and terminate at a node.
 An edge does not intersect or cross over another edge.
 Areas bounded by a set of edges and nodes are called regions.
 When counting regions, include the area outside the graph as a region too.

Figure 7.1: Procedural Design using Figure 7.2: Flow Graph Notation of given

Flowchart Flowchart

 Independent Program Path:


 Defined as a path through the program from the start node until the end node that
introduces at least one new set of processing statements or a new condition (i.e., new
nodes)
 Must move along at least one edge that has not been traversed before by a previous path
 Basis set for flow graph on previous slide
– Path 1: 0-1-11
– Path 2: 0-1-2-3-4-5-10-1-11
– Path 3: 0-1-2-3-6-8-9-10-1-11
– Path 4: 0-1-2-3-6-7-9-10-1-11
 The number of paths in the basis set is determined by the cyclomatic complexity
o cyclomatic complexity Can be computed three ways
 The number of regions
 V(G) = E – N + 2, where E is the number of edges and N is the number of nodes in
graph G
 V(G) = P + 1, where P is the number of predicate nodes in the flow graph G
 Number of regions: Bounded + unbounded rejoins of flow graph
Results in the following equations for the example flow graph

– Number of regions = 4 (R1,R2,R3 and R4)


– V(G) = 14 edges – 12 nodes + 2 = 4
– V(G) = 3 predicate nodes + 1 = 4
– Therefore, No. of Independent path = 4 (For Given Flow graph)
– Therefore, Prepare test cases that will force execution of all 4 paths.

Advantages of Basic Path Testing

 It helps to reduce the redundant tests


 It focuses attention on program logic
 It helps facilitates analytical versus arbitrary case design
 Test cases which exercise basis set will execute every statement in a program at least once.

----------------------------------------------------------------------------------------------------------------

Example 2: Consider the given program that checks if a number is prime or not. For
the following program:

int main()

1 int n, index;
2 cout << "Enter a number: " <> n;

3 index = 2;

4 while (index <= n - 1)

5 {

6 if (n % index == 0)

7 {

8 cout << "It is not a prime number" << endl;

9 break;

10 }

11 index++;

12 }

13 if (index == n)

14 cout << "It is a prime number" << endl;

15 } // end main

1 Draw the Control Flow Graph


2 Calculate the Cyclomatic complexity using all the methods
3 List all the Independent Paths
4 Design test cases from independent paths
1)Flow graph Notation
Cyclomatic complexity

Method-1:

V(G) = e - n + 2
In the above control flow graph,
where, e = 10, n = 8 and p = 1
Therefore,
Cy-clomatic Complexity V(G)
= 10 - 8 + 2
=4

Method-2:

V(G) = P+1
In the above control flow graph,
where, P = 3 (Node B, C and F)
Therefore,
Cyclomatic Complexity V(G)
=3+1
=4

Method-3:

V(G) = Number of Regions


In the above control flow graph, there are 4

2) Independent Paths:
Path 1 : A - B - F - G - H
Path 2 : A - B - F - H
Path 3 : A - B - C - E - B - F - G - H
Path 4 : A - B - C - D - F - H
Note:

 Independent paths are not necessarily unique.


 Each of these paths have introduced at least one new edge which has not been
traversed before

3) Test cases:
To derive test cases, we have to use the independent paths obtained previously. To design a
test case, provide input to the program such that each independent path is executed.
For the given program, the following test cases will be obtained:

Test case
ID Input Number Output Independent path covered

Test case
ID Input Number Output Independent Path covered

1 1 No output A-B-F-H

2 2 It is a prime number A-B-F-G-H

3 3 It is a prime number A-B-C-E-B-F-G-H

4 4 It is not a prime number A-B-C-D-F-H


PART B
(PART B : TO BE COMPLETED BY STUDENTS)

(Students must submit the soft copy as per following segments within two hours of the
practical. The soft copy must be uploaded on the Blackboard or emailed to the concerned lab in
charge faculties at the end of the practical in case the there is no Black board access available)

Roll No. : 50 Name : Swayam Kishor Vhatkar

Class : TE Comps A Batch : A3

Date of Experiment: Date of Submission:

Grade :

B.1 Observations and Learning:

(Students are expected to understand the selected topic of basic path testing and complete the
following)

1. List out one code of selected mini project (any one function or program) and draw
flow graph notation of same .(write code below that draw flow graph)

import cv2
import numpy as np
import face_recognition
import os
from datetime import datetime from
tkinter import filedialog import tkinter as tk

# Initialize a Tkinter window to ask the user for the image file root =
tk.Tk()
root.withdraw() # Hide the main Tkinter window

# Ask the user to select an image file


file_path = filedialog.askopenfilename()
# Load the image
img = cv2.imread(file_path)
imgS = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

path = 'Training_images' images = []


classNames = []
myList = os.listdir(path) print(myList)
for cl in myList:
curImg = cv2.imread(f'{path}/{cl}') images.append(curImg)
classNames.append(os.path.splitext(cl)[0])
print(classNames)

def findEncodings(images): encodeList = []


for img in images:
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) encode =
face_recognition.face_encodings(img)[0]
encodeList.append(encode)
return encodeList

def markAttendance(name):
with open('Attendance.csv', 'r+') as f: myDataList = f.readlines()

nameList = []
for line in myDataList: entry =
line.split(',')
nameList.append(entry[0])

now = datetime.now()
dtString = now.strftime('%H:%M:%S')

# Check if the name is not in the list and mark attendance


if name not in nameList:
f.writelines(f'\n{name},{dtString}')
encodeListKnown = findEncodings(images) print('Encoding Complete')

# Detect faces in the loaded image with a larger scale parameter


facesCurFrame = face_recognition.face_locations(imgS, model='cnn')
encodesCurFrame = face_recognition.face_encodings(imgS, facesCurFrame)

for faceLoc in facesCurFrame: y1, x2, y2,


x1 = faceLoc
cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 2)

for encodeFace, faceLoc in zip(encodesCurFrame, facesCurFrame):


matches = face_recognition.compare_faces(encodeListKnown, encodeFace)
faceDis =
face_recognition.face_distance(encodeListKnown, encodeFace)

matchIndex = np.argmin(faceDis)
if matches[matchIndex]:
name = classNames[matchIndex].upper() y1, x2,
y2, x1 = faceLoc
y1, x2, y2, x1 = y1 * 4, x2 * 4, y2 * 4, x1 * 4
cv2.rectangle(img, (x1, y1), (x2, y2),
(0, 255, 0), 2)
# cv2.rectangle(img, (x1, y2 - 35), (x2, y2), (0, 255, 0),
cv2.FILLED)
cv2.putText(img, name, (x1 + 6, y2 - 6),
cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2)
markAttendance(name)

# Display the image with all detected faces


cv2.imshow('image', img)
cv2.waitKey(0)
2. Derive logical complexity using 3 measures.

3. Indentify independent paths


[start] -> [Select Image File] -> [Read Image] -> [Load Training Images] -> [Encoding
Initialization] -> [Detect Faces in Loaded Image] -> [while (Loop Over Detected Faces)] ->
[Compare Encodings] -> [if (Match Found?)] -> [Mark Attendance] -> [endwhile] -> [Display
Image with Detected Faces] -> [stop]Design test case based on independent paths
identified.

B.2: Questions

1. Differentiate between white and black box testing.

Aspect White-Box Testing Black-Box Testing


Testing based on the
Testing based on the external behavior,
Definition internal structure, logic, requirements, and
and code of the software. specifications of the
software.

Clear-box testing,
Functional testing,
Also Known As Glass-box testing,
Behavioral testing.
Transparent-box testing.

Internal workings of the Functional correctness,


Focus software, code paths, and inputs, outputs, and
data flows. external behavior.
Requires knowledge of the No knowledge of internal
Tester's Knowledge internal code and system code or system architecture
architecture. is needed.
Often used for unit,
Primarily used for system
Testing Levels integration, and some
and acceptance testing.
aspects of system testing.

Test cases are derived from


Test cases are derived from
requirements, use cases,
Test Cases code analysis, code
and functional
coverage, and paths.
specifications.

Tests are designed with


Tests are designed with a
knowledge of the
Design Approach focus on the software's
software's internal
expected behavior.
structure.

Aims to achieve high code Focuses on functional and


Code Coverage coverage and exercise code requirement coverage, not
branches. code paths.
Includes statement
Includes functional,
Types coverage, branch coverage,
system, integration,
path coverage, etc.
regression, and user
acceptance testing.

Focuses on user
Effective at finding perspective, simulates
Advantages logical errors, missing real-world usage, and
code paths, and identifies functional
security defects.
vulnerabilities.

Requires deep Cannot detect code-


technical knowledge, level issues, lacks
Disadvantages time-consuming, and visibility into internal
may not cover all real- code, and may miss
world scenarios. complex logic errors.

Code review, static Usability testing,


Examples analysis, code functional testing,
walkthroughs, acceptance testing,
structural testing. system testing.

Tools like CodeLint, Tools like Selenium,


Tools SonarQube, JUnit (for JIRA, TestRail,
unit testing). LoadRunner.

2. Differentiate between functional and non functional testing.

Testers need to have


Testers need to
knowledge of the
Tester's Knowledge understand quality
software's functional
attributes and user
requirements.
expectations.
Typically applied during
Commonly applied at unit,
system, acceptance, and
Testing Levels integration, system, and
some aspects of integration
acceptance testing levels.
testing.
Test cases are derived from Test cases are designed
functional requirements, based on non-functional
Test Cases
specifications, and use requirements, guidelines,
cases. and user expectations.
Covers what the software Covers areas like
is supposed to do, such as performance, scalability,
Focus Areas
data entry, calculations, and security, usability,
data output. compatibility, etc.

Smoke testing, sanity Load testing, performance


Examples of Tests testing, regression testing, testing, security testing,
acceptance testing. usability testing.
To evaluate how well the
To validate that the
software performs
Objective software works as intended
concerning user experience
without major defects.
and quality attributes.

Measured using various


metrics and benchmarks
Primarily based on
Measures depending on the attribute
pass/fail criteria.
(e.g., response time for
performance).

Involves evaluating if
Involves validating if the the software meets
Validation Criteria software meets functional quality standards,
specifications. performance
benchmarks, and user
expectations.
Functionality Response time, throughput,
Typical Metrics completeness, correctness, error rates, security
reliability. vulnerabilities.

B.3 Conclusion: (Students must write the conclusion as per the attainment of individual
outcome listed above and learning/observation)

White box testing is focused on the internal structures and code of a software application,
whereas black box testing assesses the functionality and behavior of the application from
an external perspective.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy