SlideShare a Scribd company logo
SOFTWARE TESTING
Get the bugs out!
1
Why Test Software?
2
 Software testing enables making objective assessments
regarding the degree of conformance of the system to stated
requirements and specifications. Testing verifies that the
system meets the different requirements including, functional,
performance, reliability, security, usability and so on.
Objective Assessment: So What?
3
 Consider the role of product owner (individual or company)
 What is their responsibility regarding software?
 When to release it?
 What level or risks are tolerable?
 To answer these questions what do they need to know?
 How many bugs exist?
 What’s the likelihood of a bug happening to users
 What could that bug do to users?
 Cost of removing bugs vs cost of lost revenue vs brand
damage costs
More than finding bugs
4
 It is important for software testing to verify and validate that
the product meets the stated requirements / specifications.

What is the value of good software?
5
 Good will with customers  more revenue
 Word of mouth  sell more
 Trust  buy more
 Reduces support costs
 Allows development team to work on adding more value (new
features and feature improvements
 Greater employee morale
Types of Software Development Tests
7
 Unit testing
 Integration testing
 Functional testing
Unit testing
8
 Unit tests are used to test individual code components and
ensure that code works the way it was intended to.
 Unit tests are written and executed by developers.
 Most of the time a testing framework like JUnit or TestNG is
used.
 Test cases are typically written at a method level and executed
via automation.
Integration Testing
9
 Integration tests check if the system as a whole works.
 Integration testing is also done by developers, but rather than
testing individual components, it aims to
test across components.
 A system consists of many separate components like code,
database, web servers, etc. (more than JUST CODE)
 Integration tests are able to spot issues like wiring of
components, network access, database issues, etc.
Functional Testing
10
 Functional tests check that each feature is implemented
correctly by comparing the results for a given input against the
specification.
 Typically, this is not done at a developer level.
 Functional tests are executed by a separate testing team.
 Test cases are written based on the specification and the actual
results are compared with the expected results.
 Several tools are available for automated functional testing
like Selenium and QTP.
UNIT TESTING
11
Today's Goal
 Functions/methods are the basic building block of programs.
 Today, you'll learn to test functions, and how to design testable
functions.
12
What is a unit test?
13
 A unit test is a piece of code that invokes a unit of work and
checks one specific end result of that unit of work. If the
assumptions on the end result turn out to be wrong, the unit
test has failed. A unit test’s scope can span as little as a
method or as much as multiple classes.
Testing Functions
 Amy is writing a program. She adds functionality by defining a
new function, and adding a function call to the new function in
the main program somewhere. Now she needs to test the new
code.
 Two basic approaches to testing the new code:
1. Run the entire program
 The function is tested when it is invoked during the program
execution
2. Test the function by itself, somehow
Which do you think will be more efficient?
14
Manual Unit Test
 A unit test is a program that tests
a function to determine if it works
properly
 A manual unit test
 Gets test input from the user
 Invokes the function on the test
input
 Displays the result of the function
 How would you use a unit test to
determine that roundIt() works
correctly?
 How does the test - debug cycle
go?
def roundIt(num: float) -> int:
return int(num + .5)
# ---- manual unit test ----
x = float(input('Enter a number:'))
result = roundIt(x)
print('Result: ', result)
15
Automated Unit Test
 An automated unit test
 Invokes the function on
predetermined test input
 Checks that the function
produced the expected result
 Displays a pass / fail
message
 Advantages?
 Disadvantages?
def roundIt(num: float) -> int:
return int(num + .5)
# ---- automated unit test ----
result = roundIt(9.7)
if result == 10:
print("Test 1: PASS")
else:
print("Test 1: FAIL")
result = roundIt(8.2)
if result == 8:
print("Test 2: PASS")
else:
print("Test 2: FAIL")
16
Automated Unit Test with assert
 The assert statement
 Performs a comparison
 If the comparison is True,
does nothing
 If the comparison is False,
displays an error and stops
the program
 assert statements help us
write concise, automated
unit tests
 Demo: Run the test
def roundIt(num: float) -> int:
return int(num + .5)
# ---- automated unit test ----
result = roundIt(9.7)
assert result == 10
result = roundIt(8.2)
assert result == 8
print("All tests passed!")
17
A Shorter Test
 This is Nice.
 Two issues:
 To test the function, we have
to copy it between the "real
program" and this unit test
 Assertion failure messages
could be more helpful
To solve these, we'll use pytest,
a unit test framework
def roundIt(num: float) -> int:
return int(num + .5)
# ---- automated unit test ----
assert roundIt(9.7) == 10
assert roundIt(8.2) == 8
print("All tests passed!")
18
A pytest Unit Test
 To create a pytest Unit Test:
 Define a unit test function named
test_something
 Place one or more assertions
inside
 These tests can be located in the
same file as the "real program," as
long as you put the real program
inside a special if statement, as
shown
 To run a pytest Unit Test from
command prompt:
 pytest program.py
 Note: pytest must first be
installed...
def roundIt(num: float) -> int:
return int(num + .5)
def test_roundIt():
assert roundIt(9.7) == 10
assert roundIt(8.2) == 8
if __name__ == "__main__":
# --- "real program" here ---
19
What's with this if statement?
if __name__ == "__main__":
# --- "real program" here ---
 This if condition above is true when the
program is executed using the python
command:
 python myprog.py
 The if condition is false when the program is
executed using pytest
 pytest myprog.py
We don't want pytest to execute the main
program...
20
pytest Unit Tests
 A pytest Unit Test can have
more than one test method
 It's good practice to have a
separate test method for
each type of test
 That way, when a test fails,
you can debug the issue
more easily
def roundIt(num: float) -> int:
return int(num + .5)
# ---- automated unit test ----
def test_roundIt_rounds_up():
assert roundIt(9.7) == 10
def test_roundIt_rounds_down():
assert roundIt(8.2) == 8
21
Designing Testable Functions
 Some functions can't be
tested with an automated
unit test.
 A testable function
 Gets input from parameters
 Returns a result
 Does no input / output
# This function is not testable
def roundIt(num: float) -> int:
print(int(num + .5))
22
Python unit test tutorial
35

More Related Content

PPTX
Upstate CSCI 540 Agile Development
PPTX
Test Automation - Everything You Need To Know
PPS
Test Process
PPTX
Ch8-Software Engineering 9
PDF
Engineering Software Products: 9. testing
PPT
Automation testing material by Durgasoft,hyderabad
PDF
Scrum gathering Paris 2013 - test automation strategy for Scrum Projects
PPT
Automation Concepts
Upstate CSCI 540 Agile Development
Test Automation - Everything You Need To Know
Test Process
Ch8-Software Engineering 9
Engineering Software Products: 9. testing
Automation testing material by Durgasoft,hyderabad
Scrum gathering Paris 2013 - test automation strategy for Scrum Projects
Automation Concepts

What's hot (20)

PPTX
SE2018_Lec 20_ Test-Driven Development (TDD)
PPTX
Advanced Software Test Automation
PPTX
How to Design a Successful Test Automation Strategy
PPT
Automation Framework/QTP Framework
PPT
PDF
Acceptance test driven development
PPTX
Software Engineering- Types of Testing
PDF
Management Issues in Test Automation
PDF
Growing Object Oriented Software
PDF
It Seemed a Good Idea at the Time: Intelligent Mistakes in Test Automation
PDF
Agile Acceptance testing with Fitnesse
PPTX
Software Engineering-Part 1
PPTX
Practical Software Testing Tools
PDF
manual-testing
DOCX
Sqa unit1
PPT
Software testing basic concepts
PPTX
Synthesizing Continuous Deployment Practices in Software Development
PPTX
Software testing tools (free and open source)
PPT
Chapter 14
SE2018_Lec 20_ Test-Driven Development (TDD)
Advanced Software Test Automation
How to Design a Successful Test Automation Strategy
Automation Framework/QTP Framework
Acceptance test driven development
Software Engineering- Types of Testing
Management Issues in Test Automation
Growing Object Oriented Software
It Seemed a Good Idea at the Time: Intelligent Mistakes in Test Automation
Agile Acceptance testing with Fitnesse
Software Engineering-Part 1
Practical Software Testing Tools
manual-testing
Sqa unit1
Software testing basic concepts
Synthesizing Continuous Deployment Practices in Software Development
Software testing tools (free and open source)
Chapter 14
Ad

Similar to Upstate CSCI 540 Unit testing (20)

PPT
SE2011_10.ppt
PDF
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
PPT
Ian Sommerville, Software Engineering, 9th EditionCh 8
PPTX
Software enginnenring Book Slides By summer
PDF
Unit testing for WordPress
PPTX
1.1 Chapter_22_ Unit Testing-testing (1).pptx
PPTX
PDF
Lecture 11 Software Engineering Testing Slide
PPS
Why Unit Testingl
PPS
Why Unit Testingl
PPS
Why unit testingl
PPTX
PPTX
Software Testing adn Testing Software .pptx
PPTX
Software Testing- Introduction Software.pptx
PPT
Unit testing php-unit - phing - selenium_v2
PPT
Testing Software Solutions
PPTX
Unit tests & TDD
PPTX
Software testing
SE2011_10.ppt
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Ian Sommerville, Software Engineering, 9th EditionCh 8
Software enginnenring Book Slides By summer
Unit testing for WordPress
1.1 Chapter_22_ Unit Testing-testing (1).pptx
Lecture 11 Software Engineering Testing Slide
Why Unit Testingl
Why Unit Testingl
Why unit testingl
Software Testing adn Testing Software .pptx
Software Testing- Introduction Software.pptx
Unit testing php-unit - phing - selenium_v2
Testing Software Solutions
Unit tests & TDD
Software testing
Ad

More from DanWooster1 (20)

PPTX
Upstate CSCI 450 WebDev Chapter 9
PPTX
Upstate CSCI 450 WebDev Chapter 4
PPTX
Upstate CSCI 450 WebDev Chapter 4
PPTX
Upstate CSCI 450 WebDev Chapter 3
PPTX
Upstate CSCI 450 WebDev Chapter 2
PPTX
Upstate CSCI 450 WebDev Chapter 1
PPT
Upstate CSCI 525 Data Mining Chapter 3
PPT
Upstate CSCI 525 Data Mining Chapter 2
PPT
Upstate CSCI 525 Data Mining Chapter 1
PPTX
Upstate CSCI 200 Java Chapter 8 - Arrays
PPTX
Upstate CSCI 200 Java Chapter 7 - OOP
PPTX
CSCI 200 Java Chapter 03 Using Classes
PPTX
CSCI 200 Java Chapter 02 Data & Expressions
PPTX
CSCI 200 Java Chapter 01
PPTX
CSCI 238 Chapter 08 Arrays Textbook Slides
PPTX
Chapter 6 - More conditionals and loops
PPTX
Upstate CSCI 450 jQuery
PPTX
Upstate CSCI 450 PHP Chapters 5, 12, 13
PPTX
Upstate CSCI 450 PHP
PPTX
CSCI 238 Chapter 07 - Classes
Upstate CSCI 450 WebDev Chapter 9
Upstate CSCI 450 WebDev Chapter 4
Upstate CSCI 450 WebDev Chapter 4
Upstate CSCI 450 WebDev Chapter 3
Upstate CSCI 450 WebDev Chapter 2
Upstate CSCI 450 WebDev Chapter 1
Upstate CSCI 525 Data Mining Chapter 3
Upstate CSCI 525 Data Mining Chapter 2
Upstate CSCI 525 Data Mining Chapter 1
Upstate CSCI 200 Java Chapter 8 - Arrays
Upstate CSCI 200 Java Chapter 7 - OOP
CSCI 200 Java Chapter 03 Using Classes
CSCI 200 Java Chapter 02 Data & Expressions
CSCI 200 Java Chapter 01
CSCI 238 Chapter 08 Arrays Textbook Slides
Chapter 6 - More conditionals and loops
Upstate CSCI 450 jQuery
Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP
CSCI 238 Chapter 07 - Classes

Recently uploaded (20)

PPTX
L1 - Introduction to python Backend.pptx
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
medical staffing services at VALiNTRY
PPTX
ai tools demonstartion for schools and inter college
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
System and Network Administration Chapter 2
PPTX
Introduction to Artificial Intelligence
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
history of c programming in notes for students .pptx
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
top salesforce developer skills in 2025.pdf
L1 - Introduction to python Backend.pptx
2025 Textile ERP Trends: SAP, Odoo & Oracle
VVF-Customer-Presentation2025-Ver1.9.pptx
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
medical staffing services at VALiNTRY
ai tools demonstartion for schools and inter college
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
System and Network Administration Chapter 2
Introduction to Artificial Intelligence
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
history of c programming in notes for students .pptx
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
How to Choose the Right IT Partner for Your Business in Malaysia
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
How to Migrate SBCGlobal Email to Yahoo Easily
Operating system designcfffgfgggggggvggggggggg
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
wealthsignaloriginal-com-DS-text-... (1).pdf
top salesforce developer skills in 2025.pdf

Upstate CSCI 540 Unit testing

  • 2. Why Test Software? 2  Software testing enables making objective assessments regarding the degree of conformance of the system to stated requirements and specifications. Testing verifies that the system meets the different requirements including, functional, performance, reliability, security, usability and so on.
  • 3. Objective Assessment: So What? 3  Consider the role of product owner (individual or company)  What is their responsibility regarding software?  When to release it?  What level or risks are tolerable?  To answer these questions what do they need to know?  How many bugs exist?  What’s the likelihood of a bug happening to users  What could that bug do to users?  Cost of removing bugs vs cost of lost revenue vs brand damage costs
  • 4. More than finding bugs 4  It is important for software testing to verify and validate that the product meets the stated requirements / specifications. 
  • 5. What is the value of good software? 5  Good will with customers  more revenue  Word of mouth  sell more  Trust  buy more  Reduces support costs  Allows development team to work on adding more value (new features and feature improvements  Greater employee morale
  • 6. Types of Software Development Tests 7  Unit testing  Integration testing  Functional testing
  • 7. Unit testing 8  Unit tests are used to test individual code components and ensure that code works the way it was intended to.  Unit tests are written and executed by developers.  Most of the time a testing framework like JUnit or TestNG is used.  Test cases are typically written at a method level and executed via automation.
  • 8. Integration Testing 9  Integration tests check if the system as a whole works.  Integration testing is also done by developers, but rather than testing individual components, it aims to test across components.  A system consists of many separate components like code, database, web servers, etc. (more than JUST CODE)  Integration tests are able to spot issues like wiring of components, network access, database issues, etc.
  • 9. Functional Testing 10  Functional tests check that each feature is implemented correctly by comparing the results for a given input against the specification.  Typically, this is not done at a developer level.  Functional tests are executed by a separate testing team.  Test cases are written based on the specification and the actual results are compared with the expected results.  Several tools are available for automated functional testing like Selenium and QTP.
  • 11. Today's Goal  Functions/methods are the basic building block of programs.  Today, you'll learn to test functions, and how to design testable functions. 12
  • 12. What is a unit test? 13  A unit test is a piece of code that invokes a unit of work and checks one specific end result of that unit of work. If the assumptions on the end result turn out to be wrong, the unit test has failed. A unit test’s scope can span as little as a method or as much as multiple classes.
  • 13. Testing Functions  Amy is writing a program. She adds functionality by defining a new function, and adding a function call to the new function in the main program somewhere. Now she needs to test the new code.  Two basic approaches to testing the new code: 1. Run the entire program  The function is tested when it is invoked during the program execution 2. Test the function by itself, somehow Which do you think will be more efficient? 14
  • 14. Manual Unit Test  A unit test is a program that tests a function to determine if it works properly  A manual unit test  Gets test input from the user  Invokes the function on the test input  Displays the result of the function  How would you use a unit test to determine that roundIt() works correctly?  How does the test - debug cycle go? def roundIt(num: float) -> int: return int(num + .5) # ---- manual unit test ---- x = float(input('Enter a number:')) result = roundIt(x) print('Result: ', result) 15
  • 15. Automated Unit Test  An automated unit test  Invokes the function on predetermined test input  Checks that the function produced the expected result  Displays a pass / fail message  Advantages?  Disadvantages? def roundIt(num: float) -> int: return int(num + .5) # ---- automated unit test ---- result = roundIt(9.7) if result == 10: print("Test 1: PASS") else: print("Test 1: FAIL") result = roundIt(8.2) if result == 8: print("Test 2: PASS") else: print("Test 2: FAIL") 16
  • 16. Automated Unit Test with assert  The assert statement  Performs a comparison  If the comparison is True, does nothing  If the comparison is False, displays an error and stops the program  assert statements help us write concise, automated unit tests  Demo: Run the test def roundIt(num: float) -> int: return int(num + .5) # ---- automated unit test ---- result = roundIt(9.7) assert result == 10 result = roundIt(8.2) assert result == 8 print("All tests passed!") 17
  • 17. A Shorter Test  This is Nice.  Two issues:  To test the function, we have to copy it between the "real program" and this unit test  Assertion failure messages could be more helpful To solve these, we'll use pytest, a unit test framework def roundIt(num: float) -> int: return int(num + .5) # ---- automated unit test ---- assert roundIt(9.7) == 10 assert roundIt(8.2) == 8 print("All tests passed!") 18
  • 18. A pytest Unit Test  To create a pytest Unit Test:  Define a unit test function named test_something  Place one or more assertions inside  These tests can be located in the same file as the "real program," as long as you put the real program inside a special if statement, as shown  To run a pytest Unit Test from command prompt:  pytest program.py  Note: pytest must first be installed... def roundIt(num: float) -> int: return int(num + .5) def test_roundIt(): assert roundIt(9.7) == 10 assert roundIt(8.2) == 8 if __name__ == "__main__": # --- "real program" here --- 19
  • 19. What's with this if statement? if __name__ == "__main__": # --- "real program" here ---  This if condition above is true when the program is executed using the python command:  python myprog.py  The if condition is false when the program is executed using pytest  pytest myprog.py We don't want pytest to execute the main program... 20
  • 20. pytest Unit Tests  A pytest Unit Test can have more than one test method  It's good practice to have a separate test method for each type of test  That way, when a test fails, you can debug the issue more easily def roundIt(num: float) -> int: return int(num + .5) # ---- automated unit test ---- def test_roundIt_rounds_up(): assert roundIt(9.7) == 10 def test_roundIt_rounds_down(): assert roundIt(8.2) == 8 21
  • 21. Designing Testable Functions  Some functions can't be tested with an automated unit test.  A testable function  Gets input from parameters  Returns a result  Does no input / output # This function is not testable def roundIt(num: float) -> int: print(int(num + .5)) 22
  • 22. Python unit test tutorial 35