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

What's hot

SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)
Amr E. Mohamed
 
Advanced Software Test Automation
Advanced Software Test AutomationAdvanced Software Test Automation
Advanced Software Test AutomationUnmesh Ballal
 
Selenium Demo
Selenium DemoSelenium Demo
How to Design a Successful Test Automation Strategy
How to Design a Successful Test Automation Strategy How to Design a Successful Test Automation Strategy
How to Design a Successful Test Automation Strategy Impetus Technologies
 
Automation Framework/QTP Framework
Automation Framework/QTP FrameworkAutomation Framework/QTP Framework
Automation Framework/QTP Framework
HeyDay Software Solutions
 
Sdlc
SdlcSdlc
Acceptance test driven development
Acceptance test driven developmentAcceptance test driven development
Acceptance test driven developmentEditor Jacotech
 
Software Engineering- Types of Testing
Software Engineering- Types of TestingSoftware Engineering- Types of Testing
Software Engineering- Types of Testing
Trinity Dwarka
 
Management Issues in Test Automation
Management Issues in Test AutomationManagement Issues in Test Automation
Management Issues in Test Automation
TechWell
 
Growing Object Oriented Software
Growing Object Oriented SoftwareGrowing Object Oriented Software
Growing Object Oriented SoftwareAnnmarie Lanesey
 
It Seemed a Good Idea at the Time: Intelligent Mistakes in Test Automation
It Seemed a Good Idea at the Time: Intelligent Mistakes in Test AutomationIt Seemed a Good Idea at the Time: Intelligent Mistakes in Test Automation
It Seemed a Good Idea at the Time: Intelligent Mistakes in Test Automation
TechWell
 
Agile Acceptance testing with Fitnesse
Agile Acceptance testing with FitnesseAgile Acceptance testing with Fitnesse
Agile Acceptance testing with Fitnesse
ClareMcLennan
 
Software Engineering-Part 1
Software Engineering-Part 1Software Engineering-Part 1
Software Engineering-Part 1
Shrija Madhu
 
Practical Software Testing Tools
Practical Software Testing ToolsPractical Software Testing Tools
Practical Software Testing Tools
Dr Ganesh Iyer
 
manual-testing
manual-testingmanual-testing
manual-testing
Kanak Mane
 
Sqa unit1
Sqa unit1Sqa unit1
Sqa unit1kannaki
 
Software testing basic concepts
Software testing basic conceptsSoftware testing basic concepts
Software testing basic conceptsHưng Hoàng
 
Synthesizing Continuous Deployment Practices in Software Development
Synthesizing Continuous Deployment Practices in Software DevelopmentSynthesizing Continuous Deployment Practices in Software Development
Synthesizing Continuous Deployment Practices in Software Development
Akond Rahman
 
Software testing tools (free and open source)
Software testing tools (free and open source)Software testing tools (free and open source)
Software testing tools (free and open source)
Wael Mansour
 

What's hot (20)

SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)
 
Advanced Software Test Automation
Advanced Software Test AutomationAdvanced Software Test Automation
Advanced Software Test Automation
 
Selenium Demo
Selenium DemoSelenium Demo
Selenium Demo
 
How to Design a Successful Test Automation Strategy
How to Design a Successful Test Automation Strategy How to Design a Successful Test Automation Strategy
How to Design a Successful Test Automation Strategy
 
Automation Framework/QTP Framework
Automation Framework/QTP FrameworkAutomation Framework/QTP Framework
Automation Framework/QTP Framework
 
Sdlc
SdlcSdlc
Sdlc
 
Acceptance test driven development
Acceptance test driven developmentAcceptance test driven development
Acceptance test driven development
 
Software Engineering- Types of Testing
Software Engineering- Types of TestingSoftware Engineering- Types of Testing
Software Engineering- Types of Testing
 
Management Issues in Test Automation
Management Issues in Test AutomationManagement Issues in Test Automation
Management Issues in Test Automation
 
Growing Object Oriented Software
Growing Object Oriented SoftwareGrowing Object Oriented Software
Growing Object Oriented Software
 
It Seemed a Good Idea at the Time: Intelligent Mistakes in Test Automation
It Seemed a Good Idea at the Time: Intelligent Mistakes in Test AutomationIt Seemed a Good Idea at the Time: Intelligent Mistakes in Test Automation
It Seemed a Good Idea at the Time: Intelligent Mistakes in Test Automation
 
Agile Acceptance testing with Fitnesse
Agile Acceptance testing with FitnesseAgile Acceptance testing with Fitnesse
Agile Acceptance testing with Fitnesse
 
Software Engineering-Part 1
Software Engineering-Part 1Software Engineering-Part 1
Software Engineering-Part 1
 
Practical Software Testing Tools
Practical Software Testing ToolsPractical Software Testing Tools
Practical Software Testing Tools
 
manual-testing
manual-testingmanual-testing
manual-testing
 
Sqa unit1
Sqa unit1Sqa unit1
Sqa unit1
 
Software testing basic concepts
Software testing basic conceptsSoftware testing basic concepts
Software testing basic concepts
 
Synthesizing Continuous Deployment Practices in Software Development
Synthesizing Continuous Deployment Practices in Software DevelopmentSynthesizing Continuous Deployment Practices in Software Development
Synthesizing Continuous Deployment Practices in Software Development
 
Software testing tools (free and open source)
Software testing tools (free and open source)Software testing tools (free and open source)
Software testing tools (free and open source)
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
 

Similar to Upstate CSCI 540 Unit testing

SE2011_10.ppt
SE2011_10.pptSE2011_10.ppt
SE2011_10.ppt
MuhammedAlTijaniMrja
 
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosUnit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Flutter Agency
 
Ian Sommerville, Software Engineering, 9th EditionCh 8
Ian Sommerville,  Software Engineering, 9th EditionCh 8Ian Sommerville,  Software Engineering, 9th EditionCh 8
Ian Sommerville, Software Engineering, 9th EditionCh 8
Mohammed Romi
 
Software enginnenring Book Slides By summer
Software enginnenring Book Slides By summerSoftware enginnenring Book Slides By summer
Software enginnenring Book Slides By summer
p229279
 
Unit testing for WordPress
Unit testing for WordPressUnit testing for WordPress
Unit testing for WordPress
Harshad Mane
 
Ch8
Ch8Ch8
Ch8
Ch8Ch8
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
priya_trivedi
 
Why unit testingl
Why unit testinglWhy unit testingl
Why unit testingl
Priya Sharma
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
priya_trivedi
 
Software testing
Software testingSoftware testing
Unit testing php-unit - phing - selenium_v2
Unit testing   php-unit - phing - selenium_v2Unit testing   php-unit - phing - selenium_v2
Unit testing php-unit - phing - selenium_v2Tricode (part of Dept)
 
PHPUnit
PHPUnitPHPUnit
Testing Software Solutions
Testing Software SolutionsTesting Software Solutions
Testing Software Solutionsgavhays
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
Dror Helper
 
Software testing
Software testingSoftware testing
Software testing
Aman Adhikari
 
Testing methodology
Testing methodologyTesting methodology
Testing methodology
Dina Hanbazazah
 
Software testing
Software testingSoftware testing
Software testing
Eng Ibrahem
 
Ch8.testing
Ch8.testingCh8.testing

Similar to Upstate CSCI 540 Unit testing (20)

SE2011_10.ppt
SE2011_10.pptSE2011_10.ppt
SE2011_10.ppt
 
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosUnit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
 
Ian Sommerville, Software Engineering, 9th EditionCh 8
Ian Sommerville,  Software Engineering, 9th EditionCh 8Ian Sommerville,  Software Engineering, 9th EditionCh 8
Ian Sommerville, Software Engineering, 9th EditionCh 8
 
Software enginnenring Book Slides By summer
Software enginnenring Book Slides By summerSoftware enginnenring Book Slides By summer
Software enginnenring Book Slides By summer
 
Unit testing for WordPress
Unit testing for WordPressUnit testing for WordPress
Unit testing for WordPress
 
Ch8
Ch8Ch8
Ch8
 
Ch8
Ch8Ch8
Ch8
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Why unit testingl
Why unit testinglWhy unit testingl
Why unit testingl
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Software testing
Software testingSoftware testing
Software testing
 
Unit testing php-unit - phing - selenium_v2
Unit testing   php-unit - phing - selenium_v2Unit testing   php-unit - phing - selenium_v2
Unit testing php-unit - phing - selenium_v2
 
PHPUnit
PHPUnitPHPUnit
PHPUnit
 
Testing Software Solutions
Testing Software SolutionsTesting Software Solutions
Testing Software Solutions
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
 
Software testing
Software testingSoftware testing
Software testing
 
Testing methodology
Testing methodologyTesting methodology
Testing methodology
 
Software testing
Software testingSoftware testing
Software testing
 
Tdd dev session
Tdd dev sessionTdd dev session
Tdd dev session
 
Ch8.testing
Ch8.testingCh8.testing
Ch8.testing
 

More from DanWooster1

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

More from DanWooster1 (20)

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

Recently uploaded

Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
abdulrafaychaudhry
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 

Recently uploaded (20)

Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 

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