Skip to content

Ilm o Irfan

Technologies

  • Home
  • Courses
    • Free Courses
  • Motivational Seminars
  • Blog
  • Books
  • Contact
  • Home
  • Courses
    • Free Courses
  • Motivational Seminars
  • Blog
  • Books
  • Contact
Explore Courses

Introduction to Python

  • September 1, 2022
  • Home
  • Free Book

Table of Contents

Chapter 11 - Software Testing

  • Authors
  • Ms. Samavi Salman
  • Dr. Rao Muhammad Adeel Nawab
  • Supporting Material
  • Download Supporting Material (Code): here

Quick Recap

  • Quick Recap – Exception Handling in Python

In previous Chapter, I presented

  • Exception
    • In a Programming Language, an Exception is defined as an unplanned event (or Runtime Error), which occurs during the execution of a Program and it disrupts the normal flow of the Program’s instructions
  • Exception Handler
    • An Exception Handler is a piece of Code that stimulates what a Program will do when an Exception (Runtime Errors)  occurs in a Program
  • Exception Handling 
    • In Programming Languages, Exception Handling is defined as the mechanism of handling Exception(s) (Runtime Errors) (or Runtime Error(s))
  • Types of Exceptions in Python
    • Built in Exceptions
    • User Defined Exceptions 
  • Built in Exceptions
    • A Built-in Exception is defined as an Exception which is generated either by an Interpreter or Built-in Function
  • User Defined Exception
    • A User Defined Exception is an Exception which is written by a Programmer
  • Exception Handling using try / except
    • When we handle Exception(s) (Runtime Error(s)) using try / except 
      • try Block lets you Test a Block of Code for Exception(s) (Runtime Error(s))  and 
      • except Block lets you handle the Exception(s) (or Runtime Error(s)) that was raised in the try Block
  • Exception Handling using try / except / else
    • When we handle Exception(s) (Runtime Error(s)) using try / except / else 
      • try Block lets you Test a Block of Code for Exception(s) (or Runtime Error(s)) and 
      • except Block lets you handle the Exception (or Runtime Error) that was raised in the try Block
      • else Block of Code will be executed only if no Exception(s) is generated in try Block of Code
  • Exception Handling using try / except / finally
    • When we handle Exception(s) (Runtime Error(s)) using try / except / finally 
      • try Block lets you Test a Block of Code for Exception(s) (or Runtime Error(s)) and 
      • except Block lets you handle the Exceptions (or Runtime Error(s)) that was raised in the try Block
      • finally lets you execute Code, regardless of the result of the try and except Blocks of Code
  • Exception Handling using raise
    • A Programmer can choose to Throw (or raise) a specific Exception using raise Keyword

Testing

  • Testing
  • Definition 
    • Testing is the process of evaluating a system or its component(s) with the intent to find whether it satisfies the specified requirements or not
    • In simple words, testing is executing a system to identify gaps, errors, or missing requirements in contrary to the actual requirements
  • Purpose 
    • There are two fundamental purposes of testing: 
      • verifying procurement specifications
      • what was specified is what was delivered
      • System meets the following specifications
      • Functional requirements
      • Performance requirements
      • Design requirements
      • Implementation requirements
      • managing risk
  • Importance
    • It typically identifies at the end of the development phase of the project, establishes the criteria for project acceptance
  • Strengths 
    • Testing identifies Gaps in Knowledge 
    • Testing is necessary to provide the facilities to the customers like
    • the delivery of high-quality product or software application which requires lower maintenance cost and hence results into more accurate, consistent, and reliable results
  • Weaknesses 
    • The project requirements are changing continuously
    • Technology advancement is not available
    • Project implementation is complex
    • Integration of modules has become difficult
    • Priority conflicts are not resolved properly
    • Responsibilities have not been resolved properly
    • Lack of resources
    • Lack of training
    • Lack of planning and scheduling for the resources
    • Lack of communication in the team
  • Suitable to Use
    • When a software product is updated with new code, feature or functionality, it is tested thoroughly to detect if there is any negative impact of the added code

Software Testing

  • Software Testing
  • Definition
    • Software Testing is the process of verifying a system with the purpose of identifying errors, gaps, or missing requirement versus the actual requirement 
  • Formal Definition (ANSI/IEEE 1059 standard)
    • A process of analyzing a software item to 
      • Detect the differences between existing and required conditions (i.e., defects) 
      • Evaluate the features of the software item
  • Purpose
    • A primary purpose of testing is to 
      • Detect software failures so that defects may be discovered and corrected
      • Testing cannot establish that a product functions properly under all conditions, but only that it does not function properly under specific conditions
      • Evaluate the functionality of a software application 
      • Identify the defects to ensure that the product is defect-free to produce the quality product
  • Importance
    • Testing is important because
      • Software bugs could be expensive or even dangerous
      • Software bugs can potentially cause monetary and human loss
  • Applications
    • Cost Effective Development 
    • Product Improvement 
    • Test Automation 
    • Quality Check
    • Functionality
    • Reliability
    • Usability
    • Efficiency
    • Maintainability
    • Portability
  • Strengths
    • Cost-Effective
    • Security
    • Product quality
    • Customer Satisfaction
  • Weaknesses
    • Exhaustive (total) testing is impossible in present scenario
    • Time and likewise budget constraints normally require very careful planning of the testing effort
    • Compromise between thoroughness and budget
    • Test results are used to make business decisions for release dates

Types of Software Testing

  • Types of Software Testing
  • Software Testing can be categorized in multiple ways
    • Automated Software Testing vs Manual Software Testing

Manual Software Testing Method

  • Manual Software Testing Method
  • Definition
    • In Manual Software Testing Method, a Software is manually tested by a Human (Domain Expert)
  • Purpose
    • The purpose includes 
      • Verifying all the features 
      • Specified in requirements documents with the perspective of their end user
  • Strengths
    • Following are the advantages of Manual Testing
      • Easier to adapt to changes
      • usability and visual analysis
      • Suitable at the beginning of the project, where functionality is constantly changing and is potentially unstable
      • Easier to prepare test data
      • Manual testing can be used for exploratory testing
      • Short-term cost is lower
      • Exhaustive Plan Audit
      • Cost Effectiveness
  • Weakness
    • Some tests are difficult or almost not testable manually. E.g. performance tests
      • Risks of Disappointment
      • Requires More Time and Assets
  • Suitable to Use
    • Smaller projects
    • Application in initial stage of development. Content is changing quite often and not stabilized yet
  • Exploratory Testing
    • This type of testing requires the tester’s knowledge, experience, analytical/logical skills, creativity, and intuition
  • Usability Testing
    • This is an area in which you need to measure how user-friendly, efficient, or convenient the software or product is for the end users. Testing the look and feel of the application.
  • Ad-hoc Testing
    • In this scenario, there is no specific approach. It is an unplanned method of testing where the understanding and insight of the tester is the only important factor
  • Steps – Manual Software Testing 
  • The following Steps describe how to carry out the Manual Software Testing 
    • Step 01: Completely and Correctly Understand the Real-world Problem
      • Step 1.1: Real-world Problem
      • Step 1.2: Real-world Problem Description 
      • Step 1.3: Your Job – As a Software Developer
    • Step 02: Can we treat the Real-world Problem as a Programming Problem?
      • Step 2.1: Check Whether a Real-world Problem can be treated as a Programming Problem?
    • Step 03: Completely and Correctly Understand the Programming Problem
      • Step 3.1: Selection of Suitable Programming Language to Solve Programming Problem
      • Step 3.2: Convert Real-world Problem Description into Programming Problem Description
    • Step 02: Plan and Design Solution to the Real-world Problem
      • Step 2.1: Input-Processing-Output
    • Step 03: Implementation – Write Program (Code)
    • Step 04: Extract Input and Output from your Program (implemented in Step 03)
    • Step 05: Write Suitable and High-Quality Test Cases
      • Step 5.1: Write Test Cases for Correct Input
      • Step 5.2: Write Test Cases for Wrong Input
      • Step 5.3: Write Test Cases for (Correct) Exceptional Input
    • Step 06: Write Output Values to be produced against Input of each Test Case (called Actual Output Values)
    • Step 07: Separately Run your Program for each Test Case
      • Step 7.1: Give Input of each Test Case to Your Program and Execute it to produce Output 
      • Step 7.2: Record the Output generated by your Program against Input of each Test Case (called System Output Values)
    • Step 08: For each Test Case, compare Actual Output Value with System Output Value
  • If (Actual Output Value = System Output Value)
  • THEN
  • Test Case has Passed 
  • ELSE
  • Test Case has Failed
    • Step 09: Check Whether Program is working correctly or not?

If (All Test Cases are Passed)

THEN 

  • Program is Working Correctly  
  • Program is ready for Deployment 

ELSE

  • Program is NOT Working Correctly
  • Analyze Your Program – Why Test Case(s) Failed? 
  • Go to Step 01 to Update (and re-test) your Program, so that it Correctly Works for all Test Cases 
  • Best Practices to Write Suitable and High-Quality Test Cases
  • The Best Practices to create a High-quality Test Case are as follows
    • Write in simple and easy-to-understand language
    • Use active voice instead of passive voice
    • Use exact and consistent names (of forms, fields, etc.)
    • Test Cases need to be simple and transparent
    • Create Test Case with End User in Mind
    • Avoid test case repetition
    • Do not assume
    • Do not eat Steps
    • Test Cases must be identifiable
    • Do Not Just write Test Cases for Positive Scenarios
    • Do not Be ambiguous while writing Test Case
  • Test Cases Categories
  • Correct Input
  • Wrong Input
  • (Correct) Exceptional Input
  • Example – Manual Software Testing Method
  • In sha Allah, in the next Slides, we will try to show (with Fazal of Allah) how to Test a Program / Software using Manual Software Testing Method using the Steps mentioned above
  • Example 01 – Manual Software Testing Method Cont…
  • Step 01: Completely and Correctly Understand the Real-world Problem
Completely and Correctly Understand the Real-world Problem
Real-world Problem

Addition of Two Integer Number

Real-world Problem Description

Ms. Samavi is teaching Mathematics to her students. She needs software which can add two integer numbers, so that her students can practice and strengthen their Math Concepts of adding two integer numbers.

Your Job – As a Software Developer

As a Software Developer, your job is to help Ms. Samavi by developing and deploying a high-quality Software, which can be used by her students to practice and strengthen their Math Concepts of adding two integer numbers. 

Can we Treat the Real-world Problem as a Programming Problem?
Check Whether a Real-world Problem can be Treated as a Programming Problem
  • If (Real-world Problem can be Broken into Input and Output)
    • THEN 
      • We MAY Treat Real-world Problem as a Programming Problem 
    • ELSE
      • We CANNOT Treat Real-world Problem as a Programming Problem
Check Input and Output in the Real-world Problem
  • Input
    • Integer Number 01
    • Integer Number 02
  • Output
    • Integer Number 01 + Integer Number 02
Example – Check Input and Output in the Real-world Problem
  • Input 
    • 10
    • 15
  • Output 
    • 25
Conclusion

Yes, we MAY Treat Real-world Problem as a Programming Problem 

Completely and Correctly Understand the Programming Problem
Selection of Suitable Programming Language to Solve Programming Problem
  • There are many Programming Languages which are suitable to solve the above Real-world Problem, for example C, C++, Java, Python etc.
  • In Sha Allah, I will use Python 3.8.3
Real-world Problem Description into Programming Problem Description
Programming Problem Description
  • Write a Python Program which takes two Integer numbers as input from the User and displays the sum on the Output Screen.
  • Step 02: Plan and Design Solution to the Programming Problem
    • Step 2.1: Input-Processing-Output
Plan and Design Solution to the Programming Problem
Input-Processing-Output
  • Input
    • Data
      • Two Integer Numbers
        • Integer Number 01 (called number1)
        • Integer Number 02 (called number2)
    • Instruction(s)
      • Calculate Sum of two Integer Numbers
        • number1 + number2
  • Output
    • To Display Sum of two Integer Number on the Output Screen
  • Processing
    • Use print() Function – To Display Sum of two Integer Number on the Output Screen
  • Step 03: Implementation – Write Program (Code)
    • See Test-Case-Addition.ipynb in Code Folder
Pseudo Code and Flow Chart
Pseudo Code

Step 01: Start

Step 02: Input – An Integer Number (number1)

Step 03: Input – An Integer Number (number2)

Step 04: sum = number1 + number2

Step 05: Print – sum

Step 06: Stop

Note

  • In the above Pseudo Code
  • Step 03 and Step 03 represent Input
  • Step 04 represents Processing
  • Step 05 represents Output
Flow Chart
Implementation

Addition of Two Integer Numbers in Python

				
					"""
Program Details
---------------
__author__         = Ms. Samavi Salman
__copyright__         = Copyright (C) 2020 Ms. Samavi Salman
__license__         = Public Domain
__program__name__        = addition
__program__version__     = 1.1
__programing__language__ = python 3.8.3
__operating__system__    = Linux 18.04.1 LTS 64-bit Operating System
__IDE__                  = jupyter notebook 5.5.0
__Start__Date__          = 15-01-2021
__End__Date__            = 18-01-2021
"""
'''
Purpose of Program
------------------
The main purpose of this Program is to take two Integer numbers as input from the User and display their sum on 
the Output Screen.
'''

# Input
# Take Two Integer Numbers as Input form User
print("Enter First Integer Number: ")
number1 = int(input())
print("Enter Second Integer Number: ")
number2 = int(input())
# Processing
# Adding number1 and number2 and storing the Output (i.e. sum of two integer number)in a variable (called sum)
sum = number1 + number2
# Displaying Output
print(number1, "+", number2, "=", sum)
				
			
  • Step 04: Extract Input and Output from your Program (implemented in Step 03)
  • Input 
    • Integer Number 01 (called number1)
    • Integer Number 02 (called number2)
  • Output 
    • number1 + number2 
  • Step 05: Write Suitable and High-Quality Test Cases
    • Step 5.1: Write Test Cases for Correct Input
Test Case No.
Test Cases
Input
Actual Output Value

TC01

number1 = 10

number2 = 30

 

TC02

number1 = -50

number2 = -30

 

TC03

number1 = -10

number2 = 30

 

TC04

number1 = 10

number2 = -30

 
  • Step 05: Write Suitable and High-Quality Test Cases
    • Step 5.2: Write Test Cases for Wrong Input
Test Case No.
Test Cases
Input
Actual Output Value

TC 01

number1 = 3.5

number2 = -4.9

 

TC 02

number1 = 3.5

number2 = -4

 

TC 03

number1 = 3

number2 = -4.9

 
  • Step 05: Write Suitable and High-Quality Test Cases
    • Step 5.3: Write Test Cases for (Correct) Exceptional Input
No.
Test Case Category
Test Cases
Input
Actual Output Value

TC 01

(Correct) 

Exceptional Input 

number1 = 100000000

number2 = 100000000

 

TC 02

(Correct) 

Exceptional Input 

number1 = -100000000

number2 = -100000000

 

TC 03

(Correct) 

Exceptional Input 

number1 = 100000000

number2 = 9

 

TC 04

(Correct) 

Exceptional Input 

number1 = -100000000

number2 = 9

 
  • Step 06: Write Output Values to be produced against Input of each Test Case (called Actual Output Values)
No.
Test Case Category
Test Cases
Input
Actual Output Value

TC01

Correct Input

number1 = 10

number2 = 30

40

TC02

Correct Input

number1 = -50

number2 = -30

-80

TC03

Correct Input

number1 = -10

number2 = 30

20

TC04

Correct Input

number1 = 10

number2 = -30

-20

TC 05

Wrong Input

number1 = 3.5

number2 = -4.9

Error Message

TC 06

Wrong Input

number1 = 3.5

number2 = -4

Error Message

TC 07

Wrong Input

number1 = 3

number2 = -4.9

Error Message

TC 08

Wrong Input

number1 = ten

number2 = four

Error Message

TC 09

(Correct) 

Exceptional Input 

number1 = 5

number2 = six

Error Message

TC 10

(Correct) 

Exceptional Input 

number1 = six

number2 = 9

Error Message

TC 11

(Correct) 

Exceptional Input 

number1 = 100000000

number2 = 100000000

200000000

TC 12

(Correct) 

Exceptional Input 

number1 = -100000000

number2 = -100000000

-200000000

TC 13

(Correct) 

Exceptional Input 

number1 = 100000000

number2 = 9

100000009

TC 14

(Correct) 

Exceptional Input 

number1 = -100000000

number2 = 9

-99999991

  • Step 07: Separately Run your Program for each Test Case
    • See Test-Case-Addition.ipynb in Code Folder
    • Step 7.1: Give Input of each Test Case to Your Program and Execute it to produce Output 
Executing Test Case (For Correct Input) in Jupyter Notebook

Executing Test Case (For Wrong Input) in Jupyter Notebook

Executing Test Case (For Correct Exceptional Input) in Jupyter Notebook

 

  • Step 07: Separately Run your Program for each Test Case
    • Step 7.2: Record the Output generated by your Program against Input of each Test Case (called System Output Values)
No.
Test Case Category
Test Cases
System Output Value
Input
Actual Output Value

TC01

Correct Input

number1 = 10

number2 = 30

40

40

TC02

Correct Input

number1 = -50

number2 = -30

-80

-80

TC03

Correct Input

number1 = -10

number2 = 30

20

20

TC04

Correct Input

number1 = 10

number2 = -30

-20

-20

TC 05

Wrong Input

number1 = 3.5

number2 = -4.9

Error Message

Error Message

TC 06

Wrong Input

number1 = 3.5

number2 = -4

Error Message

Error Message

TC 07

Wrong Input

number1 = 3

number2 = -4.9

Error Message

Error Message

TC 08

Wrong Input

number1 = ten

number2 = four

Error Message

Error Message

TC 09

(Correct) 

Exceptional Input 

number1 = 5

number2 = six

Error Message

Error Message

TC 10

(Correct) 

Exceptional Input 

number1 = six

number2 = 9

Error Message

Error Message

TC 11

(Correct) 

Exceptional Input 

number1 = 100000000

number2 = 100000000

200000000

200000000

TC 12

(Correct) 

Exceptional Input 

number1 = -100000000

number2 = -100000000

-200000000

-200000000

TC 13

(Correct) 

Exceptional Input 

number1 = 100000000

number2 = 9

100000009

100000009

TC 14

(Correct) 

Exceptional Input 

number1 = -100000000

number2 = 9

-99999991

-99999991

  • Step 08: For each Test Case, compare Actual Output Value with System Output Value
  • If (Actual Output Value = System Output Value)
    • THEN
      • Test Case has Passed 
    • ELSE
      • Test Case has Failed
No.
Test Case Category
Test Cases
System Output Value
Outcome of Test Case
Input
Actual Output Value

TC01

Correct Input

number1 = 10

number2 = 30

40

40

Passed

TC02

Correct Input

number1 = -50

number2 = -30

-80

-80

Passed

TC03

Correct Input

number1 = -10

number2 = 30

20

20

Passed

TC04

Correct Input

number1 = 10

number2 = -30

-20

-20

Passed

TC 05

Wrong Input

number1 = 3.5

number2 = -4.9

Error Message

Error Message

Passed

TC 06

Wrong Input

number1 = 3.5

number2 = -4

Error Message

Error Message

Passed

TC 07

Wrong Input

number1 = 3

number2 = -4.9

Error Message

Error Message

Passed

TC 08

Wrong Input

number1 = ten

number2 = four

Error Message

Error Message

Passed

TC 09

(Correct) 

Exceptional Input 

number1 = 5

number2 = six

Error Message

Error Message

Passed

TC 10

(Correct) 

Exceptional Input 

number1 = six

number2 = 9

Error Message

Error Message

Passed

TC 11

(Correct) 

Exceptional Input 

number1 = 100000000

number2 = 100000000

200000000

200000000

Passed

TC 12

(Correct) 

Exceptional Input 

number1 = -100000000

number2 = -100000000

-200000000

-200000000

Passed

TC 13

(Correct) 

Exceptional Input 

number1 = 100000000

number2 = 9

100000009

100000009

Passed

TC 14

(Correct) 

Exceptional Input 

number1 = -100000000

number2 = 9

-99999991

-99999991

Passed

  • Step 09: If (All Test Cases are Passed)
  • Input 
    • Integer Number 01 (called number1)
    • Integer Number 02 (called number2)
  • Output 
    • number1 + number2 
Out of 14 Test Cases, 14 Test Cases Passed
  • Therefore, above Condition is False and the Outcome is that 
    • Program is NOT Working Correctly
  • Analyze Your Program – Why Test Case(s) Failed? 
    • Go to Step 01 to Update (and re-test) your Program, so that it Correctly Works for all Test Cases 
  • Analyze Your Program – Why Test Case(s) Failed? 
    • Step 01: List Down Failed Test Cases 
      • Test Cases that Failed are 
        • ZERO Test Case Failed
    • Step 02: Write down Observations 
      • Observation 01
        • All Failed Test Cases belong to the following Category of Test Cases
          • Wrong Input 
      • Observation 02
        • In all Failed Test Cases, either one or both Inputs are 
          • Integer / Float Number / String 
    • Step 03: Write Potential Problems Identified in Program based on Observations (in Step 02)
      • Potential Problem 01
        • Program does not have the ability to only take 
          • Integer Number as Input
      • Potential Problem 02
        • Program does not have the ability to generate an Error Message, if the User enters an Input, other than Integer Number (for e.g., Float Number, String etc.)
    • Step 04: Proposed Solution(s) to Solve Potential Problem(s)
      • Proposed Solution 01
        • Add Exceptional Handling functionality in Program (i.e., Test-Case-Addition.ipynb)
  • Example 02 – Manual Software Testing Method Cont…
  • Step 01: Completely and Correctly Understand the Real-world Problem
Completely and Correctly Understand the Real-world Problem
Real-world Problem

Swap Two Number

Real-world Problem Description

Ms. Samavi is teaching Math at IlmoIrfan. She wants her students to build concepts on storing values in variables and swapping them. For this purpose, she wants to develop Software which takes two numbers as input and swaps their values. She wants her students to use the Software practice and strengthen their Math Concepts. 

Your Job – As a Software Developer

As a Software Developer, your job is to help Ms. Samavi by developing and deploying a high-quality Software, which can be used by her students to practice and strengthen their Math Concepts of storing and swapping values in Variables. 

Can we Treat the Real-world Problem as a Programming Problem?
Check Whether a Real-world Problem can be Treated as a Programming Problem
  • If (Real-world Problem can be Broken into Input and Output)
    • THEN 
      • We MAY Treat Real-world Problem as a Programming Problem 
    • ELSE
      • We CANNOT Treat Real-world Problem as a Programming Problem
Check Input and Output in the Real-world Problem
  • Input
    • Number 01
    • Number 02
  • Output
    • Values of Number 01 and Number 02 are swapped
Example – Check Input and Output in the Real-world Problem
  • Example 01 – Input and Output
    • Input
      • Number 01 = 10
      • Number 02 = 15
    • Output
      • Number 01 = 15
      • Number 02 = 10
  • Example 02 – Input and Output
    • Input
      • Number 01 = 3.86
      • Number 02 = 2.59
    • Output
      • Number 01 = 2.59
      • Number 02 = 3.86
  • Example 03 – Input and Output
    • Input
      • Number 01 = 3.86
      • Number 02 = 7
    • Output
      • Number 01 = 7
      • Number 02 = 3.86
Conclusion

Yes, we MAY Treat Real-world Problem as a Programming Problem 

Completely and Correctly Understand the Programming Problem
Selection of Suitable Programming Language to Solve Programming Problem
  • There are many Programming Languages which are suitable to solve the above Real-world Problem, for example C, C++, Java, Python etc.
    • In Sha Allah, I will use Python 3.8.3
Real-world Problem Description into Programming Problem Description
Programming Problem Description

Write a Python Program which takes two Numbers as input from the User, Swap the Numbers and display the result on the Output Screen.

  • Step 02: Plan and Design Solution to the Programming Problem
    • Step 2.1: Input-Processing-Output
Plan and Design Solution to the Programming Problem
Input-Processing-Output
  • Input
    • Data
      • Two Numbers
        • Number 01 (called number1)
        • Number 02 (called number2)
    • Instruction(s)
      • Swap two Numbers
        • number1 = number2
        • number2 = number1
  • Output
    • To Display Swapped Numbers on the Output Screen
  • Processing
    • Use print() Function – To Display Swapped Numbers on the Output Screen
  • Step 03: Implementation – Write Program (Code)
    • See Test Cases for swap-numbers.ipynb in Code Folder
Pseudo Code and Flow Chart
Pseudo Code

Step 01: Start

Step 02: Input – number1

Step 03: Input – number2

Step 04: Print – Original number1 and number2

Step 05: temp = number1 (i.e., Store Value of number1 in a Variable (temp))

Step 06: number1 = number2

Step 07: number2 = temp

Step 08: Print – Swapped number1 and number2

Step 09: Stop

Note

  • In the above Pseudo Code
  • Step 02 and Step 03 represent Input
  • Step 05, Step 06 and Step 07 represent Processing
  • Step 08 represents Output
Flow Chart
Implementation

Swap Two Numbers in Python

				
					"""
Program Details
---------------
__author__           = Ms. Samavi Salman
__copyright__           = Copyright (C) 2020 Ms. Samavi Salman
__license__           = Public Domain
__program__name__        = addition
__program__version__     = 1.1
__programing__language__ = python 3.8.3
__operating__system__    = Linux 18.04.1 LTS 64-bit Operating System
__IDE__                  = jupyter notebook 5.5.0
__Start__Date__          = 15-01-2021
__End__Date__            = 18-01-2021
"""
'''
Purpose of Program
------------------
The main purpose of this Program is to: (1) take two Numbrs as Input from a User, (2) swap the values of Numbers and (3)
display the swapped Numbers on the Output Screen
'''
# Input
# Take Two Numbers as Input form User
number1 = float(input("Enter First Number: ")) 
number2 = float(input("Enter Second Number: "))
# Processing 
# Displaying original numbers before swapping
print("Numbers Before Swapping") 
print("Number 01 = ", number1, "Number 02 = ", number2)
# Processing 
# Declare a temporary Variable (temp) and store Value of number1 into temp
temp = number1
# Store value of number2 in number1. This will swap value of number1 with number2.
'''
Note that this will overwrite the existing value of number1. However, in the previous Python Statement (i.e., temp = number1),
we have stored the value of number1 in temp. Therefore, we have actual value of number1 stored in temp 😊
'''
number1 = number2 
# Store value of temp (i.e., value of number1) into number2. This will swap value of number2 with number1.
number2 = temp   
# Output
# Display values stored in number1 and number2 after swapping
print("Numbers After Swapping") 
print("Number 01 = ", number1,  "Number 02 = ", number2)

				
			
  • Step 04: Extract Input and Output from your Program (implemented in Step 03)
  • Input 
    • Number 01 (called number1)
    • Number 02 (called number2)
  • Output 
    • Values of Number 01 and Number 02 are swapped
  • Step 05: Write Suitable and High-Quality Test Cases
    • Step 5.1: Write Test Cases for Correct Input
Test Case No.
Test Cases
Input
Actual Output Value

TC01

number1 = 10

number2 = 30

 

TC02

number1 = -50

number2 = -30

 

TC03

number1 = -10

number2 = 30

 

TC04

number1 = 10

number2 = -30

 

TC 05

number1 = 3.5

number2 = 4.9

 

TC 06

number1= -5.5

number2 = -5.9

 

TC 07

number1 = 3.5

number2 = -4

 

TC 08

number1 = 3

number2 = -4.9

 
  • Step 05: Write Suitable and High-Quality Test Cases
    • Step 5.2: Write Test Cases for Wrong Input
Test Case No.
Test Cases
Input
Actual Output Value

TC 01

number1 = ten

number2 = four

 

TC 02

number1 = 5

number2 = six

 

TC 03

number1 = six

number2 = 9

 

TC 04

number1 = 6.5

number2 = six

 

TC 05

number1 = six

number2 = 9.5

 
  • Step 05: Write Suitable and High-Quality Test Cases
    • Step 5.3: Write Test Cases for (Correct) Exceptional Input
No.
Test Case Category
Test Cases
Input
Actual Output Value

TC 01

(Correct) 

Exceptional Input 

number1 = 10000000 

number2 = 20000000

 

TC 02

(Correct) 

Exceptional Input 

number1 = -20000000 

number2 = -10000000

 

TC 03

(Correct) 

Exceptional Input 

number1 = 20000000  

number2 = -9

 

TC 04

(Correct) 

Exceptional Input 

number1 = -10000000

number2 = 9

 
  • Step 06: Write Output Values to be produced against Input of each Test Case (called Actual Output Values)
No.
Test Case Category
Test Cases
Input
Actual Output Value

TC01

Correct Input

number1 = 10

number2 = 30

number1 = 30.0

number2 = 10.0

TC02

Correct Input

number1 = -50

number2 = -30

number1 = -30.0

number2 = -50.0

TC03

Correct Input

number1 = -10

number2 = 30

number1 = 30.0

number2 = -10.0

TC04

Correct Input

number1 = 10

number2 = -30

number1 = -30.0

number2 = 10.0

TC 05

Correct Input

number1 = 3.5

number2 = 4.9

number1 = 4.9

number2 = 3.5

TC 06

Correct Input

number1= -5.5

number2 = -5.9

number1= -5.9

number2 = -5.5

TC 07

Correct Input

number1 = 3.5

number2 = -4

number1 = -4.0

number2 = 3.5

TC 08

Correct Input

number1 = 3

number2 = -4.9

number1 = -4.9

number2 = 3.0

TC 09

Wrong Input 

number1 = ten

number2 = four

Error Message

TC 10

Wrong Input 

number1 = 5

number2 = six

Error Message

TC 11

Wrong Input 

number1 = six

number2 = 9

Error Message

TC 12

Wrong Input 

number1 = 6.5

number2 = six

Error Message

TC 13

Wrong Input 

number1 = six

number2 = 9.5

Error Message

TC 14

(Correct) 

Exceptional Input 

number1 = 10000000 

number2 = 20000000

number1 = 20000000.0 

number2 = 10000000.0

TC 15

(Correct) 

Exceptional Input 

number1 = -20000000 

number2 = -10000000

number1 = -10000000.0

number2 = -20000000.0

TC 16

(Correct) 

Exceptional Input 

number1 = 20000000  

number2 = -9

number1 = -9.0 

number2 = 20000000.0

TC 17

(Correct) 

Exceptional Input 

number1 = -10000000

number2 = 9

number1 = 9

number2 = -10000000.0  

  • Step 07: Separately Run your Program for each Test Case
    • See swap-manual-testing-v1.ipynb in Code Folder
    • Step 7.1: Give Input of each Test Case to Your Program and Execute it to produce Output 
Executing Test Case (For Correct Input) in Jupyter Notebook

Executing Test Case (For Wrong Input) in Jupyter Notebook

Executing Test Case (For Correct Exceptional Input) in Jupyter Notebook

  • Step 07: Separately Run your Program for each Test Case
    • Step 7.2: Record the Output generated by your Program against Input of each Test Case (called System Output Values)
No.
Test Case Category
Test Cases
System Output Value
Input
Actual Output Value

TC01

Correct Input

number1 = 10

number2 = 30

number1 = 30.0

number2 = 10.0

number1 = 30.0

number2 = 10.0

TC02

Correct Input

number1 = -50

number2 = -30

number1 = -30.0

number2 = -50.0

number1 = -30.0

number2 = -50.0

TC03

Correct Input

number1 = -10

number2 = 30

number1 = 30.0

number2 = -10.0

number1 = 30.0

number2 = -10.0

TC04

Correct Input

number1 = 10

number2 = -30

number1 = -30.0

number2 = 10.0

number1 = -30.0

number2 = 10.0

TC 05

Correct Input

number1 = 3.5

number2 = 4.9

number1 = 4.9

number2 = 3.5

number1 = 4.9

number2 = 3.5

TC 06

Correct Input

number1= -5.5

number2 = -5.9

number1= -5.9

number2 = -5.5

number1= -5.9

number2 = -5.5

TC 07

Correct Input

number1 = 3.5

number2 = -4

number1 = -4.0

number2 = 3.5

number1 = -4.0

number2 = 3.5

TC 08

Correct Input

number1 = 3

number2 = -4.9

number1 = -4.9

number2 = 3.0

number1 = -4.9

number2 = 3.0

TC 09

Wrong Input 

number1 = ten

number2 = four

Error Message

Error Message

TC 10

Wrong Input 

number1 = 5

number2 = six

Error Message

Error Message

TC 11

Wrong Input 

number1 = six

number2 = 9

Error Message

Error Message

TC 12

Wrong Input 

number1 = 6.5

number2 = six

Error Message

Error Message

TC 13

Wrong Input 

number1 = six

number2 = 9.5

Error Message

Error Message

TC 14

(Correct) 

Exceptional Input 

number1 = 10000000 

number2 = 20000000

number1 = 20000000.0 

number2 = 10000000.0

number1 = 20000000.0 

number2 = 10000000.0

TC 15

(Correct) 

Exceptional Input 

number1 = -20000000 

number2 = -10000000

number1 = -10000000.0

number2 = -20000000.0

number1 = -10000000.0

number2 = -20000000.0

TC 16

(Correct) 

Exceptional Input 

number1 = 20000000  

number2 = -9

number1 = -9.0 

number2 = 20000000.0

number1 = -9.0 

number2 = 20000000.0

TC 17

(Correct) 

Exceptional Input 

number1 = -10000000

number2 = 9

number1 = 9

number2 = -10000000.0  

number1 = 9

number2 = -10000000.0  

  • Step 08: For each Test Case, compare Actual Output Value with System Output Value
  • If (Actual Output Value = System Output Value)
    • THEN
      • Test Case has Passed 
    • ELSE
      • Test Case has Failed
No.
Test Case Category
Test Cases
System Output Value
Outcome of Test Case
Input
Actual Output Value

TC01

Correct Input

number1 = 10

number2 = 30

number1 = 30.0

number2 = 10.0

number1 = 30.0

number2 = 10.0

Passed

TC02

Correct Input

number1 = -50

number2 = -30

number1 = -30.0

number2 = -50.0

number1 = -30.0

number2 = -50.0

Passed

TC03

Correct Input

number1 = -10

number2 = 30

number1 = 30.0

number2 = -10.0

number1 = 30.0

number2 = -10.0

Passed

TC04

Correct Input

number1 = 10

number2 = -30

number1 = -30.0

number2 = 10.0

number1 = -30.0

number2 = 10.0

Passed

TC 05

Correct Input

number1 = 3.5

number2 = 4.9

number1 = 4.9

number2 = 3.5

number1 = 4.9

number2 = 3.5

Passed

TC 06

Correct Input

number1= -5.5

number2 = -5.9

number1= -5.9

number2 = -5.5

number1= -5.9

number2 = -5.5

Passed

TC 07

Correct Input

number1 = 3.5

number2 = -4

number1 = -4.0

number2 = 3.5

number1 = -4.0

number2 = 3.5

Passed

TC 08

Correct Input

number1 = 3

number2 = -4.9

number1 = -4.9

number2 = 3.0

number1 = -4.9

number2 = 3.0

Passed

TC 09

Wrong Input 

number1 = ten

number2 = four

Error Message

Error Message

Passed

TC 10

Wrong Input 

number1 = 5

number2 = six

Error Message

Error Message

Passed

TC 11

Wrong Input 

number1 = six

number2 = 9

Error Message

Error Message

Passed

TC 12

Wrong Input 

number1 = 6.5

number2 = six

Error Message

Error Message

Passed

TC 13

Wrong Input 

number1 = six

number2 = 9.5

Error Message

Error Message

Passed

TC 14

(Correct) 

Exceptional Input 

number1 = 10000000 

number2 = 20000000

number1 = 20000000.0 

number2 = 10000000.0

number1 = 20000000.0 

number2 = 10000000.0

Passed

TC 15

(Correct) 

Exceptional Input 

number1 = -20000000 

number2 = -10000000

number1 = -10000000.0

number2 = -20000000.0

number1 = -10000000.0

number2 = -20000000.0

Passed

TC 16

(Correct) 

Exceptional Input 

number1 = 20000000  

number2 = -9

number1 = -9.0 

number2 = 20000000.0

number1 = -9.0 

number2 = 20000000.0

Passed

TC 17

(Correct) 

Exceptional Input 

number1 = -10000000

number2 = 9

number1 = 9

number2 = -10000000.0  

number1 = 9

number2 = -10000000.0  

Passed

  • Step 09: If (All Test Cases are Passed)
  • Input 
    • Integer Number 01 (called number1)
    • Integer Number 02 (called number2)
  • Output 
    • number1 + number2 
Out of 17 Test Cases, 17 Test Cases Passed
  • Therefore, above Condition is False and the Outcome is that 
    • Program is NOT Working Correctly
  • Analyze Your Program – Why Test Case(s) Failed? 
    • Go to Step 01 to Update (and re-test) your Program, so that it Correctly Works for all Test Cases 
  • Analyze Your Program – Why Test Case(s) Failed? 
    • Step 01: List Down Failed Test Cases 
      • Test Cases that Failed are 
        • ZERO Test Case Failed
    • Step 02: Write down Observations 
      • Observation 01
        • All Failed Test Cases belong to the following Category of Test Cases
          • Wrong Input 
      • Observation 02
        • In all Failed Test Cases, either one or both Inputs are 
          • Integer / Float Number / String 
    • Step 03: Write Potential Problems Identified in Program based on Observations (in Step 02)
      • Potential Problem 01
        • Program does not have the ability to only take 
          • Integer Number as Input
      • Potential Problem 02
        • Program does not have the ability to generate an Error Message, if the User enters an Input, other than Integer Number (for e.g., Float Number, String etc.)
    • Step 04: Proposed Solution(s) to Solve Potential Problem(s)
      • Proposed Solution 01
        • Add Exceptional Handling functionality in Program (i.e., Test Cases for swap-numbers.ipynb)

Automatic Software Testing Method

  • Automatic Software Testing Method
  • Definition
    • Automation testing is the process of testing the software using an automation tool to find the defects
  • Purpose
    • In this process, testers execute the test scripts and generate the test results automatically by using automation tools
      • To handle time-consuming tasks
      • To handle repetitive tasks
      • To eliminate human error
      • For advanced GUI testing
      • To test load and performance
  • Example
    • Automation testing tools for functional testing are 
      • QTP/UFT
      • Selenium
  • Strengths
    • Reuse and execute the same kind of testing and repetitive tasks multiple times
    • Runs tests quickly and effectively
    • Can be cost effective
    • Consistent test runs and thus reliable result
  • Weakness
    • Automation tools can be expensive
    • Pesticide paradox can occur
    • If the same tests are repeated over and over again, eventually the same set of test cases will no longer find any new bugs
    • Tools detailed scripts will become unmaintainable
    • Tools have limitations
    • Difficult to detect look and feel issue and usability issue
    • Different skillset of the test team is required
    • Lack of Human Input on UI and Usability
  • Suitable to Use
    • Bigger projects where re-execution of the same test cases is expected in a long run
    • Regression Testing
      • Testing which requires the repeated execution of a task is best automated. E.g. test data creation
    • Load and Performance Testing
    • Unit testing
    • Data driven testing
  • Automatic Software Testing Libraries / Tools for Python
    • Robot

pip install robotframework

robot –version

      • Documentation Link
    • PyTest

pip install -U pytest

pytest –version

      • Documentation Link
    • Unittest
      • It is a module in Python, so no need of Installation
        • Documentation Link
    • DocTest
      • It is a module in Python, so no need of Installation
        • Documentation Link
    • Nose2
      • It is a module in Python, so no need of Installation
        • Documentation Link
    • Testify
      • Documentation Link

pip install testify

  • Lecture Focus
  • Insha Allah, I will use unitTest Library for designing Test Cases

Software Testing Life Cycle

  • Software Testing Life Cycle
  • Definition 
    • STLC stands for Software Testing Life Cycle. STLC is a sequence of different activities performed during the software testing process
  • Purpose
    • In the initial stages of STLC, while the software product or the application is being developed, the testing team analyzes and defines the scope of testing, entry and exit criteria and the test cases. It helps to reduce the test cycle time and enhance the product quality
    • As soon as the development phase is over, testing team is ready with test cases and start the execution. This helps in finding bugs in the early phase
    • Validating every module of software or application is necessary to ensure product precision and accuracy
  • Importance
    • There is major Importance of testing in the part of SDLC and it is better to introduce testing in the early stage of SDLC phases so it helps to identify the defects in the early stage & try to avoid the bugs & get resolve in the last critical stage. So, in the testing, we try to make the software defect free
    • Refine the agile testing process, increasing consistency and effectiveness
    • Clearly define goals and expectations for each project aspect
    • Apply time constraints to project testing
    • Ensure that each feature is tested and passing before additional features are added
    • Verify that project requirements are met
  • Characteristics
    • STLC is a fundamental part of Software Development Life Cycle (SDLC) but STLC consists of only the testing phases
    • STLC starts as soon as requirements are defined or software requirement document is shared by stakeholders
    • STLC yields a step-by-step process to ensure quality software
  • Strengths
    • Systematic testing leads to a faster testing process and enables teams to uncover and address issues faster
    • Project progress is easier to track since testing is performed with well-defined goals and phases
  • Steps - Software Testing Life Cycle
  • The main Steps of Software Testing Life Cycle are as follows
    • Step 1: Requirement Analysis
      • During this Phase, Test Team studies the requirements from a testing point of view to identify the testable requirements
    • Step 2: Test Planning
      • Test planning is the activity of establishing or updating a test plan. 
      • A test plan is a document describing the scope, approach, resources, and schedule of intended test activities.
    • Step 3: Test Case Development
      • In this phase testing team notes the detailed test cases. Along with test cases, testing team also prepares the test data for testing.
    • Step 4: Environment Setup
      • A testing environment is a setup of software and hardware for the testing teams to execute test cases.
      • The test environment involves setting up of distinct areas like:
        • Setup of Test Server
        • Network
        • Test PC Setup
        • Bug Reporting
        • Creating Test Data for the Test Environment
    • Step 5: Test Execution
      • Test execution is the process of executing the code and comparing the expected and actual results. When test execution begins, the test analysts start executing the test scripts based on test strategy allowed in the project.
    • Step 6: Test Cycle Closure
      • It involves calling out the testing team member meeting & evaluating cycle completion criteria based on Test coverage, Quality, Cost, Time, and the critical business objectives. 
      • A test closure report by the test lead is published after accomplishing the exit criteria and finishing the testing phase.
  • Characteristics of Good Test Case
  • Following are the characteristics of a good test case
    • Accurate: Exacts the purpose
    • Economical: No unnecessary steps or words
    • Traceable: Capable of being traced to requirements
    • Repeatable: Can be used to perform the test over and over
    • Reusable: Can be reused if necessary
  • Best Practices – Creating a Test Case
  • The Best Practices to create a high-quality Test Case are as follows
    • Write in simple and easy-to-understand language
    • Use active voice instead of passive voice
    • Use exact and consistent names (of forms, fields, etc.)
    • Test Cases need to be simple and transparent
    • Create Test Case with End User in Mind
    • Avoid test case repetition
    • Do not Assume
    • Do not Eat Steps
    • Test Cases must be identifiable
    • Do Not Just Write Test Cases for Positive Scenarios
    • Do not be Ambiguous While Writing Test Case
  • Example 01 – Best Practices for Test Cases
  • Given
    • Consider the Scenario, where we are creating a HTML Login Form for a Web Page, which allows the user to login to the Web Page. Following are the Validations applied to the form:
      • Username must start with alphabet
      • First character of Username must be capital
      • Username should not contain numerals
      • Password should be upto 6 digits (not more than that)
      • Password may contain numerals
      • Password may contain special Characters
  • Task
    • Writing the high-quality Test Cases
Test Cases

Test Case ID: 01

Test Designed by: Ms. Samavi

Test Priority (Low/Medium/High): High

Test Designed Date: 29th September, 2020

Module Name: Login Form

Test Executed by: Ms. Ayesha

Test Title: Verify Login Page

Test Execution Date: 2nd October, 2020

 Pre-conditions: The user must be authorized for logging in to the Web Page

#
Test Steps
Test Data
Expected Output
Actual Output
Status (Pass/ Fail)

1

Web Page will be opened in the Browser

Google Chrome

Firefox

Internet Explorer

Browser will display the Login Page

  

2

Enter Username 

Samavi

Samavi

  

3

Enter Password

Samavi

Samavi

  

4

Click on Login 

Click on Login Button

The User will be logged in and the Home Page will appear on Screen

  

 

  • Remarks
    • Very Bad Test Case
  • Reasons
    • Test Cases are of poor quality because 
      • The names are inconsistent 
      • Use of Passive Voice
      • Only Positive Scenarios are considered
      • Test Cases are ambiguous
  • Example 02 – Best Practices for Test Cases
  • Given
    • Consider the Scenario, where we are creating a HTML Login Form for a Web Page, which allows the user to login to the Web Page. Following are the Validations applied to the form:
      • Username must start with alphabet
      • First character of Username must be capital
      • Username should not contain numerals
      • Password should be up to 6 digits (not more than that)
      • Password may contain numerals
      • Password may contain special Characters
  • Task
    • Writing the high-quality Test Cases
Test Cases

Test Case ID: 01

Test Designed by: Ms. Samavi

Test Priority (Low/Medium/High): High

Test Designed Date: 29th September, 2020

Module Name: Login Form

Test Executed by: Ms. Sajal

Test Title: Verify Login Page

Test Execution Date: 2nd October, 2020

  Pre-conditions: The user must be authorized for logging in to the Web Page

#
Test Steps
Test Data
Expected Output
Actual Output
Status (Pass/ Fail)

1

Enter Username in the Text Field

Samavi

Samavi

  

2

Enter Username in the Text Field

Samavi

Samavi

  

3

Enter Username in the Text Field

18samavi

Samavi

  

4

Enter Password in the Text Field

Sam@18

Sam@18

  

5

Enter Password in the Text Field

Sama18

Sama18

  

6

Enter Password

Samavi

Samavi

  

7

Enter Password in the Text Field

Samavi@18

Samavi

Samav@

Sama18

  

 

  • Remarks
    • Bad Test Case
  • Reasons
    • Test Cases are of poor quality because 
      • The names are inconsistent 
      • Steps in Test Case are missing
      • Tester assumes that User will open the Page in Web Browser
      • Tester assumes that the user will click the Login Button
  • Example 03 – Best Practices for Test Cases
  • Given
    • Consider the Scenario, where we are creating a HTML Login Form for a Web Page, which allows the user to login to the Web Page. Following are the Validations applied to the form:
      • Username must start with alphabet
      • First character of Username must be capital
      • Username should not contain numerals
      • Password should be up to 6 digits (not more than that)
      • Password may contain numerals
      • Password may contain special Characters
  • Task
    • Writing the high-quality Test Cases
Test Cases
Test Case ID: 01Test Designed by: Ms. Samavi
Test Priority (Low/Medium/High): HighTest Designed Date: 29th September, 2020
Module Name: Login FormTest Executed by: Ms. Sajal
Test Title: Verify Login PageTest Execution Date: 2nd October, 2020

  Pre-conditions: The user must be authorized for logging in to the Web Page

#
Test Steps
Test Data
Expected Output
Actual Output
Status (Pass/ Fail)
1Open Web Page in your Browser

Google Chrome

Firefox

Internet Explorer

The Login Page will be displayed on the Browser Screen  
2Enter Username in the Text FieldSamaviSamavi  
3Enter Username in the Text FieldSamaviSamavi  
4Enter Username in the Text Field18samaviSamavi  
6Enter Password in the Text FieldSam@18Sam@18  
7Enter Password in the Text FieldSama18Sama18  
8Enter PasswordSamaviSamavi  
9Enter Password in the Text FieldSamavi@18

Samavi

Samav@

Sama18

Samavi

  
10Click on Login ButtonClick on Login ButtonThe User will be logged in and the Home Page will appear on Screen  

 

  • Remarks
    • Good Test Case
  • Reasons
    • Test Cases are of good quality because they are written by following the Best Practices 😊 
  • unitTest Tool
  • Definition 
    • The unittest module provides classes that make it easy to support these qualities for a set of tests
    • The principles of unittest are easily portable to other frameworks
  • Purpose 
    • unittest.TestCase is used to create test cases by subclassing it. The last block of the code at the bottom allows us to run all the tests just by running the file
  • Importance
    • unittest contains both a testing framework and a test runner
    • It supports test automation, sharing of setup and shutdown code for tests, aggregation of tests into collections, and independence of the tests from the reporting framework
  • Suitable to Use
    • In order to test Software (Product) we can use the Python unittest module and reduce the developer’s hassle by using automated testing
  • Installation of unitTest
    • unitTest is a built-in within python distribution and we don’t need to do any pip install to use it

Steps – Testing a Software using unitTest Library

  • Steps – Testing a Software using unitTest Library
  • Following Steps should be followed while testing a Software (Product)
    • Import the unit test module This module is in the standard library so there is no need to install
    • Create a Class. Inherit “unittest.TestCase” and pass as argument
    • Create Functions against the methods which must be tested
    • Start the method with test_
    • Pass self as first argument
    • In the Functions write the Test Case Since we inherited test from test case, we have access to all asserts
  • Example 1 – Automation Testing - Unit Testing
				
					"""
__author__ = Ms. Samavi Salman
__copyright__= Copyright (C) 2020 Ms. Samavi Salman
__license__ = Public Domain
__version__ = 1.0
"""

""" The main purpose of this Program is testing the Software (Product) by dividing it in small units and display the result on Output Screen. """

import unittest

def add(number1, number2):
"""Add Function"""
    return number1 + number2

def subtract(number1, number2):
"""Subtract Function"""
    return number1 - number2

def multiply(number1, number2):
"""Multiply Function"""
    return number1 * number2

def divide(number1, number2):
"""Divide Function"""
# if the denominator is ZERO. Raise Exception of ValueError

    if number2 == 0:
        raise ValueError('Can not divide by zero!')
        return number1 / number2
				
			
				
					# Inherit unittest.TestCase

class TestCalc(unittest.TestCase):
# Always start a Test Case method with test_functionname

# If the test name doesnot start with test_, it will be ignored

""" assertEqual indicates if result of sum of two Integers is equal to the given Integer """

def test_add(self):
    self.assertEqual(add(10, 5), 15)
    self.assertEqual(add(-1, 1), 0)
    self.assertEqual(add(-1, -1), -2)
    self.assertEqual(add(10000, 50000), 60000)

def test_subtract(self):
    self.assertEqual(subtract(10, 5), 5)
    self.assertEqual(subtract(-1, 1), -2)
    self.assertEqual(subtract(-1, -1), 0)
    self.assertEqual(subtract(-1, -1), -2)

def test_multiply(self):
    self.assertEqual(multiply(10, 5), 50)
    self.assertEqual(multiply(-1, 1), -1)
    self.assertEqual(multiply(-1, -1), 1)
    self.assertEqual(multiply(1000, 1000), 1000000)

def test_divide(self):
    self.assertEqual(divide(10, 5), 2)
    self.assertEqual(divide(-1, 1), -1)
    self.assertEqual(divide(-1, -1), 1)
    self.assertEqual(divide(5, 2), 2.5)
    self.assertEqual(divide(1500, 3), 500)

""" If the Divisor is not equal to ZERO, then a ValueError will be raised with self.assertRaises(ValueError)"""
divide(10, 0)

if __name__ == '__main__':
    unittest.main(argv=['first-arg-is-ignored'], exit=False)
				
			
  • Example 2 – Automation Testing - Unit Testing
				
					"""
__author__ = Ms. Samavi Salman
__copyright__= Copyright (C) 2020 Ms. Samavi Salman
__license__ = Public Domain
__version__ = 1.0
"""

"""
The main purpose of this Program is test the Software (Product) by dividing it in small units. Display the result on Output Screen.
"""

import unittest

def sum(number):
    return number + 1
				
			
				
					# Inherit unittest.TestCase
class TestCalc(unittest.TestCase):
# Always start a Test Case method with test_functionname
# If the test name doesnot start with test_, it will be ignored

def test_sum(self):
    """
    assertEqual indicates if result of sum of two Integers is equal to the given Integer
    """
    
    self.assertEqual(sum(10), 11)
    self.assertEqual(sum(-1), 0)
    self.assertEqual(sum(1), 2)
    self.assertEqual(sum(10000), 10001)

if __name__ == '__main__':
    unittest.main(argv=['first-arg-is-ignored'], exit=False)
				
			
  • Example 3 – Automation Testing - Unit Testing
				
					"""
__author__ = Ms. Samavi Salman
__copyright__= Copyright (C) 2020 Ms. Samavi Salman
__license__ = Public Domain
__version__ = 1.0
"""

"""
The main purpose of this Program is test the Software (Product) by dividing it in small units. Display the result on Output Screen.
"""

import unittest

def square(number):
    return number * number
				
			
				
					# Inherit unittest.TestCase
class TestCalc(unittest.TestCase):
# Always start a Test Case method with test_functionname
# If the test name doesnot start with test_, it will be ignored

def test_square(self):
    """
    assertEqual indicates if result of sum of two Integers is equal to the given Integer
    """

    self.assertEqual(square(10), 100)
    self.assertEqual(square(-1), 1)
    self.assertEqual(square(1), 1)
    self.assertEqual(square(50000), 2500000000)

if __name__ == '__main__':
    unittest.main(argv=['first-arg-is-ignored'], exit=False)
				
			
  • Example 4 – Automation Testing - Unit Testing
				
					"""
__author__ = Ms. Samavi Salman
__copyright__= Copyright (C) 2020 Ms. Samavi Salman
__license__ = Public Domain
__version__ = 1.0
"""

"""
The main purpose of this Program is to take marks of a student (in four courses) as input from the User. Calculate the Average Marks of the student in four courses and display it on the Output Screen
"""

# Ask User to enter Marks of four Courses
# Use raise Exception to check whether entered Marks are Valid of Not?
print("-------------------")
print("Average Calculator")
print("-------------------")

def average_Calculator();
    while True:    
        try:
            course01 = int(input("Enter marks in Maths: "))
            if course01 >= 0 and course01 <= 100:
                print("Marks are less than ZERO and greater than 100")
                break
            else:
                print("Invalid Marks. Please Enter Marks Greater than ZERO and less than 100")
        except ValueError:
            raise ValueError("Error: Invalid Input. Marks cannot be less than ZERO and greater than 100. Please again enter marks in Math")
             continue
    while True:
        try:
            course02 = float(input("Enter marks in English: "))
            if course02 >= 0 and course02 <= 100:
                print("Marks are less than ZERO and greater than 100")
               break
            else:
              print("Invalid Marks. Please Enter Marks Greater than ZERO and less than 100")
        except:
            raise ValueError("Error: Invalid Input. Marks cannot be less than ZERO and greater than 100. Please again enter marks in English")
             continue
    while True:   
        try:
            course03 = float(input("Enter marks in Science: "))
            if course03 >= 0 and course03 <= 100:
                print("Marks are less than ZERO and greater than 100")
                break
            else:
                print("Invalid Marks. Please Enter Marks Greater than ZERO and less than 100")
        except ValueError:

            raise ValueError("Error: Invalid Input. Marks cannot be less than ZERO and greater than 100. Please again enter marks in Science")
             continue
    while True:    
        try:
            course04 = float(input("Enter marks in Urdu"))
            if course04 >= 0 and course04  <= 100:
                print("Marks are less than ZERO and greater than 100")
                break
            else:
                print("Invalid Marks. Please Enter Marks Greater than ZERO and less than 100")
        except ValueError:
            raise ValueError("Error: Invalid Input. Marks cannot be less than ZERO and greater than 100. Please again enter marks in Urdu")
             continue
    print("------------")
    print("Sum of Marks")
    print("------------")
    sum = course01 + course02 + course03 + course04
    print("Sum of marks of 4 Courses: ", sum)
    print("-------------------")
    print("Average of Marks")
    print("-------------------")
    average = sum / 4
    print("Average Marks of 4 Courses: ", average)
				
			
				
					# Inherit unittest.TestCase
class TestCalc(unittest.TestCase):
# Always start a Test Case method with test_functionname
# If the test name doesnot start with test_, it will be ignored

def test_average(self):
    """ assertEqual indicates if result of sum of two Integers is equal to the given Integer """

    self.assertEqual(average_Calculator(80,80,50,65),68.8)
    self.assertEqual(average_Calculator(90,-60,77,55),40.4)
    self.assertEqual(average_Calculator(a,b,c,d), 1)
    self.assertEqual(average_Calculator(105,76,89,45),78.8)

if __name__ == '__main__':
    unittest.main(argv=['first-arg-is-ignored'], exit=False)
				
			

TODO and Your Turn

Todo Tasks
Your Turn Tasks
Todo Tasks

TODO Task 1

  • Task
    • Consider the following Tasks, write a Python Program using the following Manual Software Testing Steps mentioned in this Lecture i.e.
      • Completely and Correctly Understand the 
        • Real-world Problem
        • Programming Problem
      • Plan and Design Solution to the Programming Problem
        • Input-Processing-Output
      • Pseudo Code and Flow Chart
      • Implementation
        • Extract Input and Output from your Program 
      • Write Test Cases 
        • Correct Input 
        • Wrong Input
        • Exception Input
      • Write Output Values to be produced against Input of each Test Case 
      • Separately Run your Program for each Test Case
      • Give Input of each Test Case to Your Program and Execute it to produce Output 
      • Record the Output generated by your Program against Input of each Test Case (called System Output Values)
        • Compare Actual Output Value with System Output Value
      • Analyze Your Program
        • Passed Test Cases
        • Failed Test Cases
  • Note
    • Your answer should be
      • Well Justified

Task 01

  • Write a Python Program which takes two Integer numbers as Input from the User and Displays the Subtraction on the Output Screen.

Sample Output

—————————-

Sample Output 01

—————————-

Enter First Integer Number: 

10

Enter Second Integer Number: 

30

10 – 30 = -20

—————————-

Sample Output 02

—————————-

Enter First Integer Number: 

-10

Enter Second Integer Number: 

30

-10 – 30 = -40

—————————-

Sample Output 03

—————————-

Enter First Integer Number: 

10.5

Enter Second Integer Number: 

3.0h

10.5 – 3.0 = 7.5

—————————-

Sample Output 04

—————————-

Enter First Integer Number: 

-10.5

Enter Second Integer Number: 

-3.0

-10.5 – 3.0 = -13.5

—————————-

Sample Output 05

—————————-

Enter First Integer Number: 

ten

Error Message

Task 02

Write a Python Program which takes two numbers as Input from the User and Displays the Multiplication on the Output Screen.

Sample Output

—————————-

Sample Output 01

—————————-

Enter First Number: 

10

Enter Second Number: 

30

10 * 30 = 300

—————————-

Sample Output 02

—————————-

Enter First Number: 

-10

Enter Second Number: 

-30

-10 * -30 = 300

—————————-

Sample Output 03

—————————-

Enter First Number: 

10.5

Enter Second Number: 

3.0

10.5 * 3.0 = 31.5

—————————-

Sample Output 04

—————————-

Enter First Number: 

-10.5

Enter Second Number: 

-3.0

-10.5 * -3.0 = 31.5

—————————-

Sample Output 05

—————————-

Enter First Number: 

ten

Error Message

Task 03

  • Write a Python Program which takes two numbers as Input from the User and Displays the Division on the Output Screen.

Sample Output

—————————-

Sample Output 01

—————————-

Enter First Number: 

10

Enter Second Number: 

30

10 / 30 = 0.33

—————————-

Sample Output 02

—————————-

Enter First Number: 

-10

Enter Second Number: 

-30

-10 / -30 = 0.33

—————————-

Sample Output 03

—————————-

Enter First Number: 

10.5

Enter Second Number: 

3.0

10.5 / 3.0 = 3.5

—————————-

Sample Output 04

—————————-

Enter First Number: 

-10.5

Enter Second Number: 

-3.0

-10.5 / -3.0 = 3.5

—————————-

Sample Output 05

—————————-

Enter First Number: 

ten

Error Message

Your Turn Tasks

Your Turn Task 1

  • Task
    • Consider the following Tasks, write a Python Program using the following Manual Software Testing Steps mentioned in this Lecture i.e.
      • Completely and Correctly Understand the 
        • Real-world Problem
        • Programming Problem
      • Plan and Design Solution to the Programming Problem
        • Input-Processing-Output
      • Pseudo Code and Flow Chart
      • Implementation
      • Extract Input and Output from your Program 
      • Write Test Cases 
        • Correct Input 
        • Wrong Input
        • Exception Input
      • Write Output Values to be produced against Input of each Test Case 
      • Separately Run your Program for each Test Case
      • Give Input of each Test Case to Your Program and Execute it to produce Output 
      • Record the Output generated by your Program against Input of each Test Case (called System Output Values)
        • Compare Actual Output Value with System Output Value
      • Analyze Your Program
        • Passed Test Cases
        • Failed Test Cases

Chapter Summary

  • Chapter Summary

In this Chapter, I presented the following main concepts:

  • Testing 
    • Testing is the process of evaluating a system or its component(s) with the intent to find whether it satisfies the specified requirements or not
    • In simple words, testing is executing a system to identify any gaps, errors, or missing requirements in contrary to the actual requirements
  • Software Testing 
    • Software Testing is the process of verifying a system with the purpose of identifying any errors, gaps, or missing requirement versus the actual requirement 
  • Formal Definition (ANSI/IEEE 1059 standard)
    • A process of analyzing a software item to 
      • Detect the differences between existing and required conditions (i.e., defects) 
      • Evaluate the features of the software item
  • Types of Software Testing
    • Software Testing can be categorized in multiple ways
      • Automated Software Testing vs Manual Software Testing
  • Manual Software Testing Method
    • In Manual Software Testing Method, a Software is manually tested by a Human (Domain Expert)
  • Automatic Software Testing Method
    • Automation testing is the process of testing the software using an automation tool to find the defects
  • Software Testing Life Cycle
    • STLC stands for Software Testing Life Cycle. STLC is a sequence of different activities performed during the software testing process
  • unitTest Tool
    • The unittest module provides classes that make it easy to support these qualities for a set of tests
    • The principles of unittest are easily portable to other frameworks

In Next Chapter

  • In Next Chapter
  • In Sha Allah, in the next Chapter, I will present a detailed discussion on
  • Main concepts related to Debugging in Python
Chapter 10 - Exception Handling in Python
  • Previous
Chapter12 - Software Debugging
  • Next
Share this article!
Facebook
Twitter
LinkedIn
About Us

Ilm O Irfan Technologies believes that honest dedicated hard work with the ethical approach of commitment true to every word, and trust-building is the road to success in any field of business or life.

Quick Links
  • About Us
  • Contact
Useful Links
  • Privacy Policy
  • Terms and Conditions
  • Disclaimer
  • Support
  • FAQ
Subscribe Our Newsletter
Facebook Twitter Linkedin Instagram Youtube

© 2022 Ilmo Irfan. All Rights Reserved.