SlideShare a Scribd company logo
Testing for
Pragmatic People




Michael Davis
Development Leader
Plone Conference
5th November 2011
Theory



 • Code without tests is broken code
 • 100% test coverage is a minimum
 • God kills a kitten every time someone checks in code
   without a test
 • Testing will make you more attractive to the opposite
   sex
 • There's a special place in hell for people who code
   without tests
Reality



  •   Testing is hard
  •   Expensive
  •   Slow to run
  •   Maintaining
  •   Test framework keeps changing
  •   Refactoring
  •   Tests wrong
Confused Much?




                 http://www.f ickr.com/photos/39585662@N00/5331407243
                            l
Realism



• Tests are not mandatory
• However, they are ...
    • Advocated
    • Best practice
    • Helpful
    • Eminently sensible
Testing is a
    tool
Cost/Value




                                  Value of Test
                                  Cost of Test




             Testing Experience
What do we mean
by Tests


 •   Unit tests
 •   Integration tests
 •   Mock tests
 •   Doc tests
 •   Regression tests
Unit tests



  •   Much faster than integration tests
  •   For testing a small element of the code base
  •   Testing individual methods
  •   getToolByName is always a problem
  •   Get complex quickly
  •   Expensive to maintain
Doc tests



  • Primarily for describing functionality using python
    calls
  • Fails at first failure
  • Difficult to write
  • Good for documentation
Regression Tests



  • Not actually a test
  • About when and why
Mock Testing



  •   Using mock objects to run tests
  •   Useful in unit testing to mock required objects
  •   Can mock getToolByName to return the right tool
  •   Used to test the untestable
Integration Tests



  • Often called unit tests
  • Full Plone instance setup
What about Test
   Driven
 Development
Mindsets



  • Writing code - how
  • Writing test – what
  • Effects versus Mechanics
Keep It Simple



  • Minimise effort
  • Maximise reuse
Test Framework


 class TestCase(PloneSandboxLayer):
   defaultBases = (PLONE_FIXTURE,)


   def setUpZope(self, app, confgurationContext):
     import my.product
     self.loadZCML(package=my.product)
     z2.installProduct(app, PROJECTNAME)


   def setUpPloneSite(self, portal):
     self.applyProfle(portal, '%s:default' % PROJECTNAME)


   def tearDownZope(self, app):
     z2.uninstallProduct(app, PROJECTNAME)
Test Framework



 from plone.app.testing import PloneSandboxLayer
 from plone.app.testing import PLONE_FIXTURE
 from plone.app.testing import IntegrationTesting
 from plone.testing import z2
 from my.product.confg import PROJECTNAME


 class TestCase(PloneSandboxLayer):
   ....


 FIXTURE = TestCase()
 INTEGRATION_TESTING = IntegrationTesting(bases=(FIXTURE,),
 name="fxture:Integration")
Simple Test



 class TestReinstall(unittest.TestCase):
   """Ensure product can be reinstalled safely"""
   layer = INTEGRATION_TESTING


   def setUp(self):
      self.portal = self.layer['portal']


   def testReinstall(self):
      portal_setup = getToolByName(self.portal, 'portal_setup')
     portal_setup.runAllImportStepsFromProfle('profle-%s:default' %
 PROJECTNAME)
Running Tests



  bin/test -s my.product


   Ran 2 tests with 0 failures and 0 errors in 1.050 seconds.
  Tearing down left over layers:
   Tear down collective.wfform.tests.base.fixture:Integration in 0.000 seconds.
   Tear down collective.wfform.tests.base.TestCase in 0.013 seconds.
   Tear down plone.app.testing.layers.PloneFixture in 0.380 seconds.
   Tear down plone.testing.z2.Startup in 0.024 seconds.
   Tear down plone.testing.zca.LayerCleanup in 0.006 seconds.
Browser Layer



 class TestInstallation(unittest.TestCase):
   """Ensure product is properly installed"""
   layer = INTEGRATION_TESTING


   def setUp(self):
      self.portal = self.layer['portal']


   def testBrowserLayerRegistered(self):
      sm = getSiteManager(self.portal)
      layers = [o.__name__ for o in registered_layers()]
      assert 'IMyProduct' in layers
Skin Layer




 class TestInstallation(unittest.TestCase):
   """Ensure product is properly installed"""
   layer = INTEGRATION_TESTING


   def setUp(self):
      self.portal = self.layer['portal']


   def testSkinLayersInstalled(self):
      assert 'my_skin' in self.portal.portal_skins.objectIds()
      assert 'my_template' in self.portal.portal_skins.my_skin.objectIds()
Portal Type




 class TestInstallation(unittest.TestCase):
   """Ensure product is properly installed"""
   layer = INTEGRATION_TESTING


   def setUp(self):
      self.portal = self.layer['portal']


   def testTypesInstalled(self):
      portal_types = getToolByName(self.portal, 'portal_types')
      assert 'MyType' in portal_types.objectIds(), portal_types.objectIds()
Portal Types


 class TestContentType(unittest.TestCase):
   """Test content type"""
   layer = INTEGRATION_TESTING


   def setUp(self):
      self.portal = self.layer['portal']


   def testAddType(self):
      setRoles(self.portal, TEST_USER_ID, ['Manager'])
      self.portal.invokeFactory('MyType', 'mt1')
      mt1 = getattr(self.portal, 'mt1')
      mt1.setTitle('The Title of My Object')
      Assert mt1.Title() == 'The Title of My Object', mt1.Title()
Schema


 class TestContentSchema(unittest.TestCase):
   """Test content type schema"""
   layer = INTEGRATION_TESTING


   def setUp(self):
     self.portal = self.layer['portal']
     setRoles(self.portal, TEST_USER_ID, ['Manager'])
     self.portal.invokeFactory('MyType', 'mt1')
     self.mt1 = getattr(self.portal, 'mt1')


   def testSchema(self):
     schema = self.mt1.schema
     feld_ids = schema.keys()
     assert 'referenceNumber' in feld_ids
Form Validation



 class TestValidation(unittest.TestCase):
   """Test validation"""
   layer = INTEGRATION_TESTING


   def setUp(self):
      self.portal = self.layer['portal']
      setRoles(self.portal, TEST_USER_ID, ['Manager'])
      self.portal.invokeFactory('MyType', 'mt1')
      self.mt1 = getattr(self.portal, 'mt1')
      app = makerequest(self.app)
      app.REQUEST.form['name'] = 'Michael Davis'
Validation Test



   def testValidates(self):
      dummy_controller_state = ControllerState(
                        id='my_form',
                        context=s1,
                        button='submit',
                        status='success',
                        errors={},
                        next_action=None,)
      controller = self.portal.portal_form_controller object
      controller_state = controller.validate(dummy_controller_state,
 app.REQUEST, ['my_validate',])
      assert controller_state.getErrors() == {}, controller_state.getErrors()
Test Patterns




   def testValidatePrisoner(self):
     app.REQUEST.form['name'] = 6
     …
     assert len(controller_state.getErrors()) == 1
     assert controller_state.getErrors().has_key('name')
     assert controller_state.getErrors()['name'] == 'You are not a number'
Test Patterns




   def testValidateClint(self):
     app.REQUEST.form['name'] = ''
     …
     assert len(controller_state.getErrors()) == 1
     assert controller_state.getErrors().has_key('name')
     assert controller_state.getErrors()['name'] == 'You are not the man with no
 name'
CI Server
Use your tools
 responsibly

                 http://www.f ickr.com/photos/12803689@N02/4402962654
                            l

More Related Content

What's hot

Unit testing of java script and angularjs application using Karma Jasmine Fra...
Unit testing of java script and angularjs application using Karma Jasmine Fra...Unit testing of java script and angularjs application using Karma Jasmine Fra...
Unit testing of java script and angularjs application using Karma Jasmine Fra...
Samyak Bhalerao
 
Workshop quality assurance for php projects - phpdublin
Workshop quality assurance for php projects - phpdublinWorkshop quality assurance for php projects - phpdublin
Workshop quality assurance for php projects - phpdublin
Michelangelo van Dam
 
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Iakiv Kramarenko
 
Protractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsProtractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applications
Ludmila Nesvitiy
 
Easy automation.py
Easy automation.pyEasy automation.py
Easy automation.py
Iakiv Kramarenko
 
Testing React Applications
Testing React ApplicationsTesting React Applications
Testing React Applications
stbaechler
 
Good Practices On Test Automation
Good Practices On Test AutomationGood Practices On Test Automation
Good Practices On Test Automation
Gustavo Labbate Godoy
 
Сергей Больщиков "Protractor Tips & Tricks"
Сергей Больщиков "Protractor Tips & Tricks"Сергей Больщиков "Protractor Tips & Tricks"
Сергей Больщиков "Protractor Tips & Tricks"
Fwdays
 
Clean tests good tests
Clean tests   good testsClean tests   good tests
Clean tests good tests
Shopsys Framework
 
Unit Testing JavaScript Applications
Unit Testing JavaScript ApplicationsUnit Testing JavaScript Applications
Unit Testing JavaScript Applications
Ynon Perek
 
Gems Of Selenium
Gems Of SeleniumGems Of Selenium
Gems Of Selenium
Skills Matter
 
Intro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJSIntro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJS
Jim Lynch
 
Let's talk testing with Selenium
Let's talk testing with SeleniumLet's talk testing with Selenium
Let's talk testing with Seleniumanishanarang
 
Web ui tests examples with selenide, nselene, selene & capybara
Web ui tests examples with  selenide, nselene, selene & capybaraWeb ui tests examples with  selenide, nselene, selene & capybara
Web ui tests examples with selenide, nselene, selene & capybara
Iakiv Kramarenko
 
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
Ortus Solutions, Corp
 
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
Iakiv Kramarenko
 
Test-Driven Development of AngularJS Applications
Test-Driven Development of AngularJS ApplicationsTest-Driven Development of AngularJS Applications
Test-Driven Development of AngularJS Applications
FITC
 
Polyglot automation - QA Fest - 2015
Polyglot automation - QA Fest - 2015Polyglot automation - QA Fest - 2015
Polyglot automation - QA Fest - 2015
Iakiv Kramarenko
 
Automating Django Functional Tests Using Selenium on Cloud
Automating Django Functional Tests Using Selenium on CloudAutomating Django Functional Tests Using Selenium on Cloud
Automating Django Functional Tests Using Selenium on Cloud
Jonghyun Park
 

What's hot (20)

Unit testing of java script and angularjs application using Karma Jasmine Fra...
Unit testing of java script and angularjs application using Karma Jasmine Fra...Unit testing of java script and angularjs application using Karma Jasmine Fra...
Unit testing of java script and angularjs application using Karma Jasmine Fra...
 
Workshop quality assurance for php projects - phpdublin
Workshop quality assurance for php projects - phpdublinWorkshop quality assurance for php projects - phpdublin
Workshop quality assurance for php projects - phpdublin
 
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
 
Protractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsProtractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applications
 
Easy automation.py
Easy automation.pyEasy automation.py
Easy automation.py
 
Testing React Applications
Testing React ApplicationsTesting React Applications
Testing React Applications
 
Good Practices On Test Automation
Good Practices On Test AutomationGood Practices On Test Automation
Good Practices On Test Automation
 
Сергей Больщиков "Protractor Tips & Tricks"
Сергей Больщиков "Protractor Tips & Tricks"Сергей Больщиков "Protractor Tips & Tricks"
Сергей Больщиков "Protractor Tips & Tricks"
 
Clean tests good tests
Clean tests   good testsClean tests   good tests
Clean tests good tests
 
Unit Testing JavaScript Applications
Unit Testing JavaScript ApplicationsUnit Testing JavaScript Applications
Unit Testing JavaScript Applications
 
Gems Of Selenium
Gems Of SeleniumGems Of Selenium
Gems Of Selenium
 
Intro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJSIntro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJS
 
Let's talk testing with Selenium
Let's talk testing with SeleniumLet's talk testing with Selenium
Let's talk testing with Selenium
 
TDD, BDD and mocks
TDD, BDD and mocksTDD, BDD and mocks
TDD, BDD and mocks
 
Web ui tests examples with selenide, nselene, selene & capybara
Web ui tests examples with  selenide, nselene, selene & capybaraWeb ui tests examples with  selenide, nselene, selene & capybara
Web ui tests examples with selenide, nselene, selene & capybara
 
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
 
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
Selenide Alternative in Practice - Implementation & Lessons learned [Selenium...
 
Test-Driven Development of AngularJS Applications
Test-Driven Development of AngularJS ApplicationsTest-Driven Development of AngularJS Applications
Test-Driven Development of AngularJS Applications
 
Polyglot automation - QA Fest - 2015
Polyglot automation - QA Fest - 2015Polyglot automation - QA Fest - 2015
Polyglot automation - QA Fest - 2015
 
Automating Django Functional Tests Using Selenium on Cloud
Automating Django Functional Tests Using Selenium on CloudAutomating Django Functional Tests Using Selenium on Cloud
Automating Django Functional Tests Using Selenium on Cloud
 

Similar to Testing for Pragmatic People

Token Testing Slides
Token  Testing SlidesToken  Testing Slides
Token Testing Slides
ericholscher
 
Plone testingdzug tagung2010
Plone testingdzug tagung2010Plone testingdzug tagung2010
Plone testingdzug tagung2010Timo Stollenwerk
 
Тестирование и Django
Тестирование и DjangoТестирование и Django
Тестирование и Django
MoscowDjango
 
Testing Django Applications
Testing Django ApplicationsTesting Django Applications
Testing Django Applications
Honza Král
 
Django’s nasal passage
Django’s nasal passageDjango’s nasal passage
Django’s nasal passageErik Rose
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
Steven Smith
 
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
FalafelSoftware
 
Testing ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETTesting ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NET
Ben Hall
 
Unit testing with Spock Framework
Unit testing with Spock FrameworkUnit testing with Spock Framework
Unit testing with Spock Framework
Eugene Dvorkin
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFX
Hendrik Ebbers
 
Unit tests and TDD
Unit tests and TDDUnit tests and TDD
Unit tests and TDD
Roman Okolovich
 
The Future is Now: Writing Automated Tests To Grow Your Code
The Future is Now: Writing Automated Tests To Grow Your CodeThe Future is Now: Writing Automated Tests To Grow Your Code
The Future is Now: Writing Automated Tests To Grow Your Code
Isaac Murchie
 
Test in action – week 1
Test in action – week 1Test in action – week 1
Test in action – week 1Yi-Huan Chan
 
Developer testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing FanaticDeveloper testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing Fanatic
LB Denker
 
Building unit tests correctly
Building unit tests correctlyBuilding unit tests correctly
Building unit tests correctly
Dror Helper
 
Testing Angular
Testing AngularTesting Angular
Testing Angular
Lilia Sfaxi
 
AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...
AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...
AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...
Amazon Web Services
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Roy de Kleijn
 
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
Dror Helper
 

Similar to Testing for Pragmatic People (20)

Token Testing Slides
Token  Testing SlidesToken  Testing Slides
Token Testing Slides
 
UPC Testing talk 2
UPC Testing talk 2UPC Testing talk 2
UPC Testing talk 2
 
Plone testingdzug tagung2010
Plone testingdzug tagung2010Plone testingdzug tagung2010
Plone testingdzug tagung2010
 
Тестирование и Django
Тестирование и DjangoТестирование и Django
Тестирование и Django
 
Testing Django Applications
Testing Django ApplicationsTesting Django Applications
Testing Django Applications
 
Django’s nasal passage
Django’s nasal passageDjango’s nasal passage
Django’s nasal passage
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
 
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
 
Testing ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETTesting ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NET
 
Unit testing with Spock Framework
Unit testing with Spock FrameworkUnit testing with Spock Framework
Unit testing with Spock Framework
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFX
 
Unit tests and TDD
Unit tests and TDDUnit tests and TDD
Unit tests and TDD
 
The Future is Now: Writing Automated Tests To Grow Your Code
The Future is Now: Writing Automated Tests To Grow Your CodeThe Future is Now: Writing Automated Tests To Grow Your Code
The Future is Now: Writing Automated Tests To Grow Your Code
 
Test in action – week 1
Test in action – week 1Test in action – week 1
Test in action – week 1
 
Developer testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing FanaticDeveloper testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing Fanatic
 
Building unit tests correctly
Building unit tests correctlyBuilding unit tests correctly
Building unit tests correctly
 
Testing Angular
Testing AngularTesting Angular
Testing Angular
 
AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...
AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...
AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
 
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
 

Recently uploaded

Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 

Recently uploaded (20)

Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 

Testing for Pragmatic People

  • 1. Testing for Pragmatic People Michael Davis Development Leader Plone Conference 5th November 2011
  • 2. Theory • Code without tests is broken code • 100% test coverage is a minimum • God kills a kitten every time someone checks in code without a test • Testing will make you more attractive to the opposite sex • There's a special place in hell for people who code without tests
  • 3. Reality • Testing is hard • Expensive • Slow to run • Maintaining • Test framework keeps changing • Refactoring • Tests wrong
  • 4. Confused Much? http://www.f ickr.com/photos/39585662@N00/5331407243 l
  • 5. Realism • Tests are not mandatory • However, they are ... • Advocated • Best practice • Helpful • Eminently sensible
  • 7. Cost/Value Value of Test Cost of Test Testing Experience
  • 8. What do we mean by Tests • Unit tests • Integration tests • Mock tests • Doc tests • Regression tests
  • 9. Unit tests • Much faster than integration tests • For testing a small element of the code base • Testing individual methods • getToolByName is always a problem • Get complex quickly • Expensive to maintain
  • 10. Doc tests • Primarily for describing functionality using python calls • Fails at first failure • Difficult to write • Good for documentation
  • 11. Regression Tests • Not actually a test • About when and why
  • 12. Mock Testing • Using mock objects to run tests • Useful in unit testing to mock required objects • Can mock getToolByName to return the right tool • Used to test the untestable
  • 13. Integration Tests • Often called unit tests • Full Plone instance setup
  • 14. What about Test Driven Development
  • 15. Mindsets • Writing code - how • Writing test – what • Effects versus Mechanics
  • 16. Keep It Simple • Minimise effort • Maximise reuse
  • 17. Test Framework class TestCase(PloneSandboxLayer): defaultBases = (PLONE_FIXTURE,) def setUpZope(self, app, confgurationContext): import my.product self.loadZCML(package=my.product) z2.installProduct(app, PROJECTNAME) def setUpPloneSite(self, portal): self.applyProfle(portal, '%s:default' % PROJECTNAME) def tearDownZope(self, app): z2.uninstallProduct(app, PROJECTNAME)
  • 18. Test Framework from plone.app.testing import PloneSandboxLayer from plone.app.testing import PLONE_FIXTURE from plone.app.testing import IntegrationTesting from plone.testing import z2 from my.product.confg import PROJECTNAME class TestCase(PloneSandboxLayer): .... FIXTURE = TestCase() INTEGRATION_TESTING = IntegrationTesting(bases=(FIXTURE,), name="fxture:Integration")
  • 19. Simple Test class TestReinstall(unittest.TestCase): """Ensure product can be reinstalled safely""" layer = INTEGRATION_TESTING def setUp(self): self.portal = self.layer['portal'] def testReinstall(self): portal_setup = getToolByName(self.portal, 'portal_setup') portal_setup.runAllImportStepsFromProfle('profle-%s:default' % PROJECTNAME)
  • 20. Running Tests bin/test -s my.product Ran 2 tests with 0 failures and 0 errors in 1.050 seconds. Tearing down left over layers: Tear down collective.wfform.tests.base.fixture:Integration in 0.000 seconds. Tear down collective.wfform.tests.base.TestCase in 0.013 seconds. Tear down plone.app.testing.layers.PloneFixture in 0.380 seconds. Tear down plone.testing.z2.Startup in 0.024 seconds. Tear down plone.testing.zca.LayerCleanup in 0.006 seconds.
  • 21. Browser Layer class TestInstallation(unittest.TestCase): """Ensure product is properly installed""" layer = INTEGRATION_TESTING def setUp(self): self.portal = self.layer['portal'] def testBrowserLayerRegistered(self): sm = getSiteManager(self.portal) layers = [o.__name__ for o in registered_layers()] assert 'IMyProduct' in layers
  • 22. Skin Layer class TestInstallation(unittest.TestCase): """Ensure product is properly installed""" layer = INTEGRATION_TESTING def setUp(self): self.portal = self.layer['portal'] def testSkinLayersInstalled(self): assert 'my_skin' in self.portal.portal_skins.objectIds() assert 'my_template' in self.portal.portal_skins.my_skin.objectIds()
  • 23. Portal Type class TestInstallation(unittest.TestCase): """Ensure product is properly installed""" layer = INTEGRATION_TESTING def setUp(self): self.portal = self.layer['portal'] def testTypesInstalled(self): portal_types = getToolByName(self.portal, 'portal_types') assert 'MyType' in portal_types.objectIds(), portal_types.objectIds()
  • 24. Portal Types class TestContentType(unittest.TestCase): """Test content type""" layer = INTEGRATION_TESTING def setUp(self): self.portal = self.layer['portal'] def testAddType(self): setRoles(self.portal, TEST_USER_ID, ['Manager']) self.portal.invokeFactory('MyType', 'mt1') mt1 = getattr(self.portal, 'mt1') mt1.setTitle('The Title of My Object') Assert mt1.Title() == 'The Title of My Object', mt1.Title()
  • 25. Schema class TestContentSchema(unittest.TestCase): """Test content type schema""" layer = INTEGRATION_TESTING def setUp(self): self.portal = self.layer['portal'] setRoles(self.portal, TEST_USER_ID, ['Manager']) self.portal.invokeFactory('MyType', 'mt1') self.mt1 = getattr(self.portal, 'mt1') def testSchema(self): schema = self.mt1.schema feld_ids = schema.keys() assert 'referenceNumber' in feld_ids
  • 26. Form Validation class TestValidation(unittest.TestCase): """Test validation""" layer = INTEGRATION_TESTING def setUp(self): self.portal = self.layer['portal'] setRoles(self.portal, TEST_USER_ID, ['Manager']) self.portal.invokeFactory('MyType', 'mt1') self.mt1 = getattr(self.portal, 'mt1') app = makerequest(self.app) app.REQUEST.form['name'] = 'Michael Davis'
  • 27. Validation Test def testValidates(self): dummy_controller_state = ControllerState( id='my_form', context=s1, button='submit', status='success', errors={}, next_action=None,) controller = self.portal.portal_form_controller object controller_state = controller.validate(dummy_controller_state, app.REQUEST, ['my_validate',]) assert controller_state.getErrors() == {}, controller_state.getErrors()
  • 28. Test Patterns def testValidatePrisoner(self): app.REQUEST.form['name'] = 6 … assert len(controller_state.getErrors()) == 1 assert controller_state.getErrors().has_key('name') assert controller_state.getErrors()['name'] == 'You are not a number'
  • 29. Test Patterns def testValidateClint(self): app.REQUEST.form['name'] = '' … assert len(controller_state.getErrors()) == 1 assert controller_state.getErrors().has_key('name') assert controller_state.getErrors()['name'] == 'You are not the man with no name'
  • 31. Use your tools responsibly http://www.f ickr.com/photos/12803689@N02/4402962654 l