Plone Testing
DZUG Tagung Dresden 2010
       Timo Stollenwerk
Timo Stollenwerk
●   Plone Entwickler seit 2004
●   GSoC 2009: plone.app.discussion
    ●   ~ 120 Tests
    ●   Python und Javascript
    ●   Code Analysis (Pylint, ZPTLint, JSLint)
    ●   Code Coverage
    ●   Continuous Integration
Material
●   Folien:
    ●   slideshare.net/tisto
●   Code:
    ●   svn.plone.org/svn/collective/examples/example.dzu
        gconference/example.dzugconference
Was ist ein Test?
Test Beispiel
def is_palindrome(word):
  pass


def test_palindromic_word():
  assert is_palindrome("noon") == True
  assert is_palindrome("foo") == False
Python Unittest Testcase
import unittest
class TestIsPalindrome(unittest.TestCase):


   def test_palindromic_word():
       self.assertEquals(is_palindrome("noon"), True)
       self.failIf(is_palindrome("foo"))


   def test_non_string_raises_exception():
       self.UnlessRaises(TypeError, is_palindrome, 2)


http://docs.python.org/library/unittest.html
Warum sind Tests wichtig?
Warum Testen?
●   Robusterer Code
●   Besseres Code Verständnis
●   Nachweis
●   Dokumentation von Software Anforderungen
●   „Billigeres“ Bugfixing
●   Refactoring
Was ist Test-Driven Development?
Test-Driven Development




Kent Beck: Test Driven Development
Arten von Tests
Funktionale Tests
●   Funktionaler Ablauf
●   Benutzersicht
●   BlackBox Testing
●   Akzeptanztests
XP/Scrum und Funktionale Tests
●   Abbildung von (Software) Anforderungen durch
    User Stories / Acceptance Tests
●   Testbare Spezifikation
●   Code der die Tests besteht
●   => Beweist das die Software tut was sie soll
User Stories mit (Doc)Tests
As a logged-in user, I can add a new page to the
website.
Beispiel Funktionaler Doctest
>>> browser.open(portal_url)


>>> browser.getLink(id='example-dzugconference-
presenter').click()


>>> browser.getControl(name='form.widgets.title').value =
"Presenter 1"


>>> browser.getControl(name='form.buttons.save').click()


Plone SVN: plone.app.discussion/.../presenter.txt
zope.testbrowser
●   browser.open('http://nohost/plone/')
●   browser.getLink(link_text).click()
●   browser.url
●   browser.reload()
●   browser.getControl(input_name).value =
    ‘Whatever’
●   browser.getControl(name='form.buttons.save').
    click()

http://pypi.python.org/pypi/zope.testbrowser
zope.testbrowser debugging
open('/tmp/testbrowser.html','w').write(browser.co
ntents)
Interlude (Interaktives Debugging)
import interlude
suite = DocFileSuite(...,
     globs={'interact': interlude.interact},
...)


>>> interact( locals() )



http://pypi.python.org/pypi/interlude/
Testing Pyramide
Integrationstests
●   Testet die Zusammenarbeit voneinander
    abhängiger Komponenten
Beispiel Integrationstest
class IPresenter(form.Schema):


  title = schema.TextLine(
             title=_(u"Title")
        )


  ...
Was wollen wir testen?
●   Schema
●   Typ Registrierung (FTI)
●   Factory
●   Hinzufügen des Inhaltstyps
●   View
Integrationstests: setUp
def setUp(self):


  self.portal = self.layer['portal']


  setRoles(self.portal, TEST_USER_NAME, ['Manager'])
  self.portal.invokeFactory('Folder', 'test-folder')
  setRoles(self.portal, TEST_USER_NAME, ['Member'])


  self.folder = self.portal['test-folder']
Integrationstest: Schema
def test_schema(self):


  fti = queryUtility(IDexterityFTI,
    name='example.dzugconference.presenter')
  schema = fti.lookupSchema()


  self.assertEquals(IPresenter, schema)
Integrationstest: FTI
def test_fti(self):


  fti = queryUtility(IDexterityFTI,
     name='example.dzugconference.presenter')


  self.assertNotEquals(None, fti)
Integrationstest: Factory
def test_factory(self):


  fti = queryUtility(IDexterityFTI,
     name='example.dzugconference.presenter')
  factory = fti.factory
  new_object = createObject(factory)


  self.failUnless(
     IPresenter.providedBy(new_object))
Integrationstest: Hinzufügen
def test_adding(self):


  self.folder.invokeFactory(
     'example.dzugconference.presenter',
     'presenter1')
  p1 = self.folder['presenter1']


  self.failUnless(IPresenter.providedBy(p1))
Integrationstest: View
def test_view(self):


  self.folder.invokeFactory(
     'example.dzugconference.presenter',
     'presenter1')
  p1 = self.folder['presenter1']
  view = p1.restrictedTraverse('@@view')


  self.failUnless(view)
Integrationstest: Debugging
def test_todo(self):


  import pdb; pdb.set_trace()


  import ipdb; ipdb.set_trace()
Testing Pyramide
Unit Tests in Plone
●   Test einer isolierten Komponente
●   Wie?
●   => Mock Objects
Mock und Fake Objekte
 ●   Externe Datenbanken
 ●   Web Services
 ●   Plone Komponenten
 ●   Netzwerkverbindungen
 ●   Benötigen externe Komponenten




http://plone.org/products/dexterity/documentation/manual/developer-manual/testing/mock-testing

http://pypi.python.org/pypi/plone.mocktestcase
Setup Tests
●   Professional Plone Development
●   Layer / collective.testcaselayer
●   plone.testing / plone.app.testing
Test Setup (PPD)
TestPortlet(CinemaContentTestCase):


    def afterSetUp(self):
          …


    ...



PPD: Optilux Code Examples
Test Setup (Layer)
class CommentTest(PloneTestCase):
    layer = DiscussionLayer


    def afterSetUp(self):
         …


   ...


http://svn.plone.org/svn/plone/plone.app.discussion/trunk
Test Setup (plone.testing)
class
ExampleDzugConference(PloneSandboxLayer):
    defaultBases = (PLONE_FIXTURE,)


    def setUpPloneSite(self, portal):
          …


    ...

Collective SVN: examples/examples.dzugconference
Testrunner
parts += test


[test]
recipe = zc.recipe.testrunner
eggs = ${instance:eggs}
defaults = ['--auto-color', '--auto-progress']
Test Geschwindigkeit
Integrations-Tests vs. Funktionale Tests

●   plone.app.discussion
    ●   Test Setup (Plone Site): 9,5 Sekunden
    ●   116 Integrationstests: 15 Sekunden      (+ 6,5)
    ●   1 Funktionaler Test:   21.5 Sekunden (+ 12,0)
Testing Pyramide
Test Abdeckung
buildout.cfg



[coverage-test]
recipe = zc.recipe.testrunner
eggs = ${test:eggs}
defaults = ['--coverage', '../../coverage', '-v', '--auto-progress']


[coverage-report]
recipe = zc.recipe.egg
eggs = z3c.coverage
arguments = ('coverage', 'report')
Hudson Continuous Integration




http://hudson.zmag.de/hudson
Weitere Tests
 ●   Python
      ●   Pylint
 ●   Templates
      ●   ZPTLint
 ●   Javascript
      ●   JSLint
      ●   qUnit



svn.plone.org/svn/plone/plone.app.discussion/trunk/test-plone-4.0.x.cfg
Weiterführendes Material
●   Kent Beck: Test Driven Development
●   Python Testing: Beginner's Guide
●   Tarek Ziadé: Expert Python Programming
●   Testing in Plone:
    http://plone.org/documentation/kb/testing
●   Dexterity Manual - Testing:
    http://plone.org/products/dexterity/documentatio
    n/manual/developer-manual/testing
Fragen?

More Related Content

PDF
Plone Testing Tools And Techniques
PPT
Scryent: Plone - Hone Your Test Fu
PDF
Modern Python Testing
PPTX
Automated php unit testing in drupal 8
PDF
Token Testing Slides
ODT
Testing in-python-and-pytest-framework
PDF
Auto testing!
PDF
Doing the Impossible
Plone Testing Tools And Techniques
Scryent: Plone - Hone Your Test Fu
Modern Python Testing
Automated php unit testing in drupal 8
Token Testing Slides
Testing in-python-and-pytest-framework
Auto testing!
Doing the Impossible

What's hot (20)

PPT
Presentation_C++UnitTest
PDF
Writing good unit test
PDF
Test all the things! Automated testing with Drupal 8
ODP
Automated testing in Python and beyond
 
PPT
Stopping the Rot - Putting Legacy C++ Under Test
PDF
TDD in Python With Pytest
PDF
Oh so you test? - A guide to testing on Android from Unit to Mutation
PPTX
Unit testing presentation
ODP
Grails unit testing
PPT
20111018 boost and gtest
PPT
How to test models using php unit testing framework?
PDF
Django Testing
PPTX
Grails Spock Testing
PDF
Unit test-using-spock in Grails
PPT
PHP Unit Testing
PPT
Automated Unit Testing
ODP
Testing In Java
PPTX
Automation testing with Drupal 8
PPT
Google C++ Testing Framework in Visual Studio 2008
PPT
Getting Started with Test-Driven Development at Midwest PHP 2021
Presentation_C++UnitTest
Writing good unit test
Test all the things! Automated testing with Drupal 8
Automated testing in Python and beyond
 
Stopping the Rot - Putting Legacy C++ Under Test
TDD in Python With Pytest
Oh so you test? - A guide to testing on Android from Unit to Mutation
Unit testing presentation
Grails unit testing
20111018 boost and gtest
How to test models using php unit testing framework?
Django Testing
Grails Spock Testing
Unit test-using-spock in Grails
PHP Unit Testing
Automated Unit Testing
Testing In Java
Automation testing with Drupal 8
Google C++ Testing Framework in Visual Studio 2008
Getting Started with Test-Driven Development at Midwest PHP 2021
Ad

Viewers also liked (6)

ODP
Plone i18n, LinguaPlone
PPTX
'Wicked' Policy Challenges: Tools, Strategies and Directions for Driving Ment...
ODP
Intro to Testing in Zope, Plone
PDF
A Taste of Python - Devdays Toronto 2009
PDF
Plone TuneUp challenges
PDF
Adobe Connect Audio Conference Bridge
Plone i18n, LinguaPlone
'Wicked' Policy Challenges: Tools, Strategies and Directions for Driving Ment...
Intro to Testing in Zope, Plone
A Taste of Python - Devdays Toronto 2009
Plone TuneUp challenges
Adobe Connect Audio Conference Bridge
Ad

Similar to Plone testingdzug tagung2010 (20)

PDF
UPC Testing talk 2
PDF
PresentationqwertyuiopasdfghUnittest.pdf
PDF
Effective testing with pytest
PDF
Testing Django Applications
PDF
Making the most of your Test Suite
PDF
Test Driven Development With Python
PPTX
Testing Spring Applications
PDF
Testing for Pragmatic People
PDF
Тестирование и Django
PDF
Flink Forward Berlin 2017: Maciek Próchniak - TouK Nussknacker - creating Fli...
PPTX
Testing Django APIs
PDF
E2E testing con nightwatch.js - Drupalcamp Spain 2018
PDF
PDF
Unit Testing - The Whys, Whens and Hows
PDF
Leveling Up With Unit Testing - php[tek] 2023
PPTX
In search of JavaScript code quality: unit testing
PPT
Testing And Drupal
PDF
Django for mobile applications
PDF
Testing the frontend
PPTX
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
UPC Testing talk 2
PresentationqwertyuiopasdfghUnittest.pdf
Effective testing with pytest
Testing Django Applications
Making the most of your Test Suite
Test Driven Development With Python
Testing Spring Applications
Testing for Pragmatic People
Тестирование и Django
Flink Forward Berlin 2017: Maciek Próchniak - TouK Nussknacker - creating Fli...
Testing Django APIs
E2E testing con nightwatch.js - Drupalcamp Spain 2018
Unit Testing - The Whys, Whens and Hows
Leveling Up With Unit Testing - php[tek] 2023
In search of JavaScript code quality: unit testing
Testing And Drupal
Django for mobile applications
Testing the frontend
Testes? Mas isso não aumenta o tempo de projecto? Não quero...

More from Timo Stollenwerk (20)

PDF
German Aerospace Center (DLR) Web Relaunch
PDF
Performance Testing (Python Barcamp Cologne 2020)
PDF
Python & JavaScript
PDF
Roadmap to a Headless Plone
PDF
Plone.restapi - a bridge to the modern web
PDF
Divide et impera
PDF
The Butler and The Snake (Europython 2015)
PDF
Hypermedia APIs mit Javascript und Python
PDF
Plone Testing & Continuous Integration Team Report 2014
PDF
The Beauty and the Beast - Modern Javascript Development with AngularJS and P...
PDF
The Butler and the Snake - JCICPH
PDF
The Butler and the Snake - Continuous Integration for Python
PDF
AngularJS & Plone
PDF
Who let the robot out? Qualitativ hochwertige Software durch Continuous Integ...
PDF
PDF
Who let the robot out? - Building high quality software with Continuous Integ...
PDF
The Future Is Written - Building next generation Plone sites with plone.app.c...
PDF
Plone Einführung
PDF
Einführung Test-driven Development
PDF
Test-Driven Development
German Aerospace Center (DLR) Web Relaunch
Performance Testing (Python Barcamp Cologne 2020)
Python & JavaScript
Roadmap to a Headless Plone
Plone.restapi - a bridge to the modern web
Divide et impera
The Butler and The Snake (Europython 2015)
Hypermedia APIs mit Javascript und Python
Plone Testing & Continuous Integration Team Report 2014
The Beauty and the Beast - Modern Javascript Development with AngularJS and P...
The Butler and the Snake - JCICPH
The Butler and the Snake - Continuous Integration for Python
AngularJS & Plone
Who let the robot out? Qualitativ hochwertige Software durch Continuous Integ...
Who let the robot out? - Building high quality software with Continuous Integ...
The Future Is Written - Building next generation Plone sites with plone.app.c...
Plone Einführung
Einführung Test-driven Development
Test-Driven Development

Plone testingdzug tagung2010