SlideShare una empresa de Scribd logo
1 de 14
Testing
Will Weaver
What I Mean by Testing?
•

Automatic and repeatable checking that code
written works as expected.
•
•

Correct side effects

•
•

Correct result

Speedy enough

Writing tests prior to writing code
Why Test?
•

Reduce regression bugs

•

Increase code quality
•
•

•

Better design
Find problems early

Helps you know when you are done coding
Levels of Testing
•

Unit

•

Integration

•

System / End-to-End

•

Acceptance
Unit Testing
•

Testing small units

•

Test all cases / scenarios

•

Mock / Patch external calls
Unit Test Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# transaction.py
class Transaction(object):
def __init__(self, action, amount):
self.action = action
self.amount = amount

# bank_account.py
class BankAccount(object):
def __init__(self, initial_balance=0):
self.balance = initial_balance
self.transactions = [Transaction('initial', initial_balance)]
Unit Test Example (cont'd)
17 # test_bank_account.py
18 class DescribeBankAccount(BaseTestCase):
19
20
# Arrange
21
@classmethod
22
def configure(cls):
23
cls.init_balance = 10.0
24
cls.transaction = cls.create_patch('bank_account.Transaction')
25
26
# Act
27
@classmethod
28
def execute(cls):
29
cls.bank_account = BankAccount(cls.init_balance)
30
31
# Assert
32
def should_have_balance(self):
33
self.assertEqual(self.bank_account.balance, self.init_balance)
34
35
def should_create_transaction(self):
36
self.transaction.assert_called_once_with('initial', self.init_balance)
37
38
def should_have_transactions(self):
39
self.assertEqual(
40
self.bank_account.transactions, [self.transaction.return_value])
Integration Testing
•

Test interaction with dependencies / external
calls

•

Not as detailed as unit tests - no need to test
every scenario

•

Minimal mocking / patching
Integration Test Example
17 # test_bank_account.py
18 class DescribeBankAccount(BaseTestCase):
19
20
# Arrange
21
@classmethod
22
def configure(cls):
23
cls.init_balance = 10.0
24
25
# Act
26
@classmethod
27
def execute(cls):
28
cls.bank_account = BankAccount(cls.init_balance)
29
30
# Assert
31
def should_have_transactions(self):
32
self.assertEqual(
33
self.bank_account.transactions,
34
[Transaction('initial', self.init_balance)],
35
)
System / End-to-End Testing
•

Test public endpoints

•

Use full stack

•

No mocking / patching

•

Minimal to no inspecting of underlying side
effects - only results of calls

•

Run in a staging environment
System Test Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

# transaction.py
class Transaction(object):
def __init__(self, action, amount):
self.action = action
self.amount = amount

# bank_account.py
class BankAccount(object):
def __init__(self, initial_balance=0):
self._balance = initial_balance
self._transactions = [Transaction('initial', initial_balance)]
def deposit(self, amount):
self._balance += amount
self._transactions.append(Transaction('deposit', amount))
def withdraw(self, amount):
self._balance -= amount
self._transactions.append(Transaction('withdrawal', amount))
def get_transactions(self):
return self._transactions
System Test Example (cont’d)
28 # test_bank_account.py
29 class WhenDepositingToBankAccount(BaseTestCase):
30
31
# Arrange
32
@classmethod
33
def configure(cls):
34
cls.bank_account = BankAccount(100.0)
35
36
# Act
37
@classmethod
38
def execute(cls):
39
cls.bank_account.deposit(20.0)
40
cls.bank_account.deposit(25.0)
41
cls.bank_account.withdrawal(10.0)
42
cls.bank_account.withdrawal(5.0)
43
cls.transactions = cls.bank_account.get_transactions()
44
45
# Assert
46
def should_have_transactions(self):
47
self.assertEqual(len(self.transactions), 5)
Acceptance Testing
•

Fulfill user stories

•

Can be written and/or manual

•

Could be written by someone other than
developer - stakeholder

•

Full stack

•

Run against staging environment
Acceptance Testing
Frameworks
•

https://pypi.python.org/pypi/behave

•

http://robotframework.org/

•

A few more found here:
https://wiki.python.org/moin/PythonTestingToolsT
axonomy#Acceptance.2FBusiness_Logic_Testin
g_Tools

Más contenido relacionado

La actualidad más candente

Introduction to software testing
Introduction to software testingIntroduction to software testing
Introduction to software testing
Abhishek Saxena
 

La actualidad más candente (19)

Automation using ibm rft
Automation using ibm rftAutomation using ibm rft
Automation using ibm rft
 
Continuous performance: Load testing for developers with gatling
Continuous performance: Load testing for developers with gatlingContinuous performance: Load testing for developers with gatling
Continuous performance: Load testing for developers with gatling
 
PowerShell Functions
PowerShell FunctionsPowerShell Functions
PowerShell Functions
 
Rft courseware
Rft coursewareRft courseware
Rft courseware
 
Testing JavaScript
Testing JavaScriptTesting JavaScript
Testing JavaScript
 
UXD Practicum - eMagine Point of Sale
UXD Practicum -  eMagine Point of SaleUXD Practicum -  eMagine Point of Sale
UXD Practicum - eMagine Point of Sale
 
Implementing Blackbox Testing
Implementing Blackbox TestingImplementing Blackbox Testing
Implementing Blackbox Testing
 
Introduction to software testing
Introduction to software testingIntroduction to software testing
Introduction to software testing
 
Pluses and minuses of retesting
Pluses and minuses of retestingPluses and minuses of retesting
Pluses and minuses of retesting
 
Automate test, tools, advantages, and disadvantages
Automate test, tools, advantages,  and disadvantagesAutomate test, tools, advantages,  and disadvantages
Automate test, tools, advantages, and disadvantages
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
 
BDD
BDDBDD
BDD
 
Tibco business events (be) online training institute
Tibco business events (be) online training instituteTibco business events (be) online training institute
Tibco business events (be) online training institute
 
Equivalence class testing
Equivalence  class testingEquivalence  class testing
Equivalence class testing
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Process State vs. Object State: Modeling Best Practices for Simple Workflows ...
Process State vs. Object State: Modeling Best Practices for Simple Workflows ...Process State vs. Object State: Modeling Best Practices for Simple Workflows ...
Process State vs. Object State: Modeling Best Practices for Simple Workflows ...
 
Automation testing
Automation testingAutomation testing
Automation testing
 
EasyTest Test Automation Tool Introduction
EasyTest Test Automation Tool IntroductionEasyTest Test Automation Tool Introduction
EasyTest Test Automation Tool Introduction
 

Destacado

Destacado (6)

Objective-C for Java Developers
Objective-C for Java DevelopersObjective-C for Java Developers
Objective-C for Java Developers
 
Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual
 
파이썬+클래스+구조+이해하기 20160310
파이썬+클래스+구조+이해하기 20160310파이썬+클래스+구조+이해하기 20160310
파이썬+클래스+구조+이해하기 20160310
 
SEO: Getting Personal
SEO: Getting PersonalSEO: Getting Personal
SEO: Getting Personal
 
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika AldabaLightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
 
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job? Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
 

Similar a Testing

Bdd for-dso-1227123516572504-8
Bdd for-dso-1227123516572504-8Bdd for-dso-1227123516572504-8
Bdd for-dso-1227123516572504-8
Frédéric Delorme
 
Tdd for BT E2E test community
Tdd for BT E2E test communityTdd for BT E2E test community
Tdd for BT E2E test community
Kerry Buckley
 
Frozen rails 2012 - Fighting Code Smells
Frozen rails 2012 - Fighting Code SmellsFrozen rails 2012 - Fighting Code Smells
Frozen rails 2012 - Fighting Code Smells
Dennis Ushakov
 
Acceptance Testing With Selenium
Acceptance Testing With SeleniumAcceptance Testing With Selenium
Acceptance Testing With Selenium
elliando dias
 

Similar a Testing (20)

Unit Testing - The Whys, Whens and Hows
Unit Testing - The Whys, Whens and HowsUnit Testing - The Whys, Whens and Hows
Unit Testing - The Whys, Whens and Hows
 
Bdd for-dso-1227123516572504-8
Bdd for-dso-1227123516572504-8Bdd for-dso-1227123516572504-8
Bdd for-dso-1227123516572504-8
 
Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Tdd for BT E2E test community
Tdd for BT E2E test communityTdd for BT E2E test community
Tdd for BT E2E test community
 
TDD, BDD and mocks
TDD, BDD and mocksTDD, BDD and mocks
TDD, BDD and mocks
 
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
 
TDD
TDDTDD
TDD
 
Testing Django Applications
Testing Django ApplicationsTesting Django Applications
Testing Django Applications
 
Test Driven Development Introduction
Test Driven Development IntroductionTest Driven Development Introduction
Test Driven Development Introduction
 
Никита Галкин "Testing in Frontend World"
Никита Галкин "Testing in Frontend World"Никита Галкин "Testing in Frontend World"
Никита Галкин "Testing in Frontend World"
 
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in FlexassertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
 
VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)
 
Getting Started With Testing
Getting Started With TestingGetting Started With Testing
Getting Started With Testing
 
Frozen rails 2012 - Fighting Code Smells
Frozen rails 2012 - Fighting Code SmellsFrozen rails 2012 - Fighting Code Smells
Frozen rails 2012 - Fighting Code Smells
 
Testing in FrontEnd World by Nikita Galkin
Testing in FrontEnd World by Nikita GalkinTesting in FrontEnd World by Nikita Galkin
Testing in FrontEnd World by Nikita Galkin
 
Acceptance Testing With Selenium
Acceptance Testing With SeleniumAcceptance Testing With Selenium
Acceptance Testing With Selenium
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 

Testing

  • 2. What I Mean by Testing? • Automatic and repeatable checking that code written works as expected. • • Correct side effects • • Correct result Speedy enough Writing tests prior to writing code
  • 3. Why Test? • Reduce regression bugs • Increase code quality • • • Better design Find problems early Helps you know when you are done coding
  • 5. Unit Testing • Testing small units • Test all cases / scenarios • Mock / Patch external calls
  • 6. Unit Test Example 1 2 3 4 5 6 7 8 9 10 11 12 13 14 # transaction.py class Transaction(object): def __init__(self, action, amount): self.action = action self.amount = amount # bank_account.py class BankAccount(object): def __init__(self, initial_balance=0): self.balance = initial_balance self.transactions = [Transaction('initial', initial_balance)]
  • 7. Unit Test Example (cont'd) 17 # test_bank_account.py 18 class DescribeBankAccount(BaseTestCase): 19 20 # Arrange 21 @classmethod 22 def configure(cls): 23 cls.init_balance = 10.0 24 cls.transaction = cls.create_patch('bank_account.Transaction') 25 26 # Act 27 @classmethod 28 def execute(cls): 29 cls.bank_account = BankAccount(cls.init_balance) 30 31 # Assert 32 def should_have_balance(self): 33 self.assertEqual(self.bank_account.balance, self.init_balance) 34 35 def should_create_transaction(self): 36 self.transaction.assert_called_once_with('initial', self.init_balance) 37 38 def should_have_transactions(self): 39 self.assertEqual( 40 self.bank_account.transactions, [self.transaction.return_value])
  • 8. Integration Testing • Test interaction with dependencies / external calls • Not as detailed as unit tests - no need to test every scenario • Minimal mocking / patching
  • 9. Integration Test Example 17 # test_bank_account.py 18 class DescribeBankAccount(BaseTestCase): 19 20 # Arrange 21 @classmethod 22 def configure(cls): 23 cls.init_balance = 10.0 24 25 # Act 26 @classmethod 27 def execute(cls): 28 cls.bank_account = BankAccount(cls.init_balance) 29 30 # Assert 31 def should_have_transactions(self): 32 self.assertEqual( 33 self.bank_account.transactions, 34 [Transaction('initial', self.init_balance)], 35 )
  • 10. System / End-to-End Testing • Test public endpoints • Use full stack • No mocking / patching • Minimal to no inspecting of underlying side effects - only results of calls • Run in a staging environment
  • 11. System Test Example 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 # transaction.py class Transaction(object): def __init__(self, action, amount): self.action = action self.amount = amount # bank_account.py class BankAccount(object): def __init__(self, initial_balance=0): self._balance = initial_balance self._transactions = [Transaction('initial', initial_balance)] def deposit(self, amount): self._balance += amount self._transactions.append(Transaction('deposit', amount)) def withdraw(self, amount): self._balance -= amount self._transactions.append(Transaction('withdrawal', amount)) def get_transactions(self): return self._transactions
  • 12. System Test Example (cont’d) 28 # test_bank_account.py 29 class WhenDepositingToBankAccount(BaseTestCase): 30 31 # Arrange 32 @classmethod 33 def configure(cls): 34 cls.bank_account = BankAccount(100.0) 35 36 # Act 37 @classmethod 38 def execute(cls): 39 cls.bank_account.deposit(20.0) 40 cls.bank_account.deposit(25.0) 41 cls.bank_account.withdrawal(10.0) 42 cls.bank_account.withdrawal(5.0) 43 cls.transactions = cls.bank_account.get_transactions() 44 45 # Assert 46 def should_have_transactions(self): 47 self.assertEqual(len(self.transactions), 5)
  • 13. Acceptance Testing • Fulfill user stories • Can be written and/or manual • Could be written by someone other than developer - stakeholder • Full stack • Run against staging environment
  • 14. Acceptance Testing Frameworks • https://pypi.python.org/pypi/behave • http://robotframework.org/ • A few more found here: https://wiki.python.org/moin/PythonTestingToolsT axonomy#Acceptance.2FBusiness_Logic_Testin g_Tools

Notas del editor

  1. Result – inputs -> outputs Side Effects – Car model -> start engine -> update boolean engine running Speedy – app needing 1000 calls per second Tests prior – instead of throwing together tests at the end – plan ahead
  2. Regression – knowing previous code won’t brake Design – break up code into small pieces Done coding – good design == confidence
  3. Unit – small units – possibly mocking out external dependencies Integration – testing units with their dependencies to make sure interactions work System – Calling only public API endpoints/functions and using the full stack Acceptance – automated based on user stories – could be written by someone other than developer - or just manual user testing
  4. BaseTestCase - built on top of unittest
  5. Generally would have API calls for a system running on a staging environment, but this I hope still shows the difference