SlideShare una empresa de Scribd logo
1 de 37
Intro to Testing in Zope, Plone Andriy Mylenkyy © Quintagroup, 2008
What we'll talk about ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Testing intro ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
unittest ,[object Object],[object Object],[object Object]
unittest.py TestSuite  TestCase TC TC TC TestSuite(TS)
unittest: TestCase ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],run(result)  result.startTest() result.stopTest() testMethod() setUp() tearDown() debug
unittest: module members ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
unittest: module members (cont.) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
unittest: TestSuite / TestCase  import unittest as ut class WidgetTC(ut.TestCase): def setUp(self): ... def tearDown(self): ... def testDefaultSize(self): assertEqual(...) def testResize(self): self.failIf(...) def otherTest(self): self.assertRaises(...) if __name__ == '__main__': # 1 # ut.main() #1b# ut.main(defaultTest='WidgetTC') #2,3# suite = ut.TestSuite() # 2 # suite.addTest(ut.makeSuite(WidgetTC)) # 3 # suite.addTest('WidgetTC('otherTest')) #2,3# runner = ut.TextTestRunner() #2,3# runner.run(sute) TestSuite _tests WidgetTC("testDefaultSize") WidgetTC("testResize") unittest.makeSuite(WidgetTC)
unittest: command line mytest.py ---------------------------------------------- import unittest class WidgetTC(unittest.TestCase): ... if __name__ == '__main__': unittest.main() ----------------------------------------------- $ python mytest.py .. OK ------------------------------------------------- $ python mytest.py WidgetTC.testDefaultSize WidgetTC.testResize .. OK ------------------------------------------------- $ python mytest.py -v testDefaultSize (__main__.WidgetTC) ... ok testResize (__main__.WidgetTC) ... ok ... OK
doctest ,[object Object],[object Object]
import types, mymodule, doctest def hasInt(*args): """  Test is integer value present in args. >>> hasInt("the string") False >>> hasInt("the string", 1) True """ args = list(args) while args: if type(args.pop()) == types.IntType: return True return False __test__  = {'My module test' : mymodule, 'My string test' : “””>>>1==1 True“””} if __name__ == '__main__':  doctest.testmod() doctest: bases ,[object Object],[object Object],[object Object],[object Object]
doctest: testmod/testfile ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
doctest: Option flags ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Test ELLIPSIS option >>> range(100)  #doctest:+ELLIPSIS [0, ..., 99] >>> range(100) [0, ..., 99] import doctest “”” >>>  range(100) [0, ..., 99] “”” doctest.testmod( optionflags=doctest.ELLIPSIS)
doctest: Unittest Support ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],“”” >>>  range(100)[0, ..., 99] “”” import doctest, unittest if __name__ == “__main__”: suite = unittest.TestSuite() testrunner = unittest.TextTestRunner() testrunner.run(doctest.DocTestSuite(optionflags=doctest.ELLIPSIS)) # testrunner.run(doctest.DocTestSuite())
doctest: Internal structure object DocTes t Example Example Example result DocTestFinder DocTestRunner
zope.testing ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
zope.testing: Lyaers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],setUp tearDown setUp tearDown TestCase TestCase TestCase
zope.testing: Lyaers (cont) class  BaseLayer : @classmethod def  setUp (cls): “ Layer setup ” @classmethod def  tearDown (cls): “ Layer teardown ” @classmethod def  testSetUp (cls): “ Before each test setup ” @classmethod def  testTearDown (cls): “ After each test teardown ” class MyTestCase(TestCase): layer = NestedLayer def setUp(self): pass def tearDown(self): pass class NestedLayer( BaseLayer) : @classmethod def  setUp (cls): “ Layer setup ” @classmethod def  tearDown (cls): “ Layer teardown ” testrunner.py --path', directory_with_tests --layer 112 --layer Unit'.split
zope.testing: Levels ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],TestCase TestCase TestCase TestCase TestCase TestCase Level  1 Level  2 TestCase TestCase TestCase Level - 3
zope.testing: Test selection ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
zope.testing: options (cont) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
zope.testing: test.py script ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
zope.testing: examples ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ZopeTestCase(ZTC) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ZTC: framework.py vs test.py ,[object Object],[object Object],[object Object],[object Object],[object Object],import os from ZODB.DemoStorage import DemoStorage from ZODB.FileStorage import FileStorage db = os.path.join('..', '..', '..', 'var', 'Data.fs') db = os.path.abspath(db) Storage = DemoStorage(base=FileStorage(db, read_only=1))
ZTC: ZopeTestCase.py ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ZTC: Entrypoints setUp(self) try: self. beforeSetUp() self.app = self._app() self._setup() self. afterSetUp() except: self._clear() raise tearDown(self) try: self. beforeTearDown() self._clear(1) except: self._clear() raise Before ALL ZTC Folder,  UserFolder,  User, login After  Fixture created   ConnectionRegistry Before delete  folder from self.app After folder delete Before close  connection to ZODB beforeClose() afterClear() After ALL Zope.APP Opens a ZODB connection  Request.__of__(app)
ZTC: Class diagram
ZTC: Writing Tests ,[object Object],[object Object],[object Object],[object Object]
ZTC: Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
PortalTestCase ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
PortalTestCase (cont) ,[object Object],setUp(self) try: self. beforeSetUp() self.app = self._app() self.portal = self._portal() self._setup() self. afterSetUp() except: self._clear() raise _portal(self) return self.getPortal() getPortal(self) return getattr(self.app, poratl)
PloneTestCase(PTC) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
PTC: PloneTestCase (cont) ,[object Object],[object Object],[object Object],[object Object],[object Object]
PTC: PloneTestCase example import os, sys if __name__ == '__main__': execfile(os.path.join(sys.path[0], 'framework.py')) from Products.PloneTestCase import PloneTestCase PloneTestCase.setupPloneSite() class TestDocument(PloneTestCase.PloneTestCase): def afterSetUp(self): ... def testAddDocument(self): self.failUnless(...) def test_suite(): ... return suite if __name__ == '__main__': framework()
Resources ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

Más contenido relacionado

La actualidad más candente

White paper for unit testing using boost
White paper for unit testing using boostWhite paper for unit testing using boost
White paper for unit testing using boost
nkkatiyar
 
Test in action week 2
Test in action   week 2Test in action   week 2
Test in action week 2
Yi-Huan Chan
 
Grails/Groovyによる開発事例紹介
Grails/Groovyによる開発事例紹介Grails/Groovyによる開発事例紹介
Grails/Groovyによる開発事例紹介
Kiyotaka Oku
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoin
knight1128
 
Selenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalks
Selenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalksSelenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalks
Selenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalks
Lohika_Odessa_TechTalks
 
Clojure - A new Lisp
Clojure - A new LispClojure - A new Lisp
Clojure - A new Lisp
elliando dias
 

La actualidad más candente (20)

White paper for unit testing using boost
White paper for unit testing using boostWhite paper for unit testing using boost
White paper for unit testing using boost
 
JUnit Pioneer
JUnit PioneerJUnit Pioneer
JUnit Pioneer
 
Perl Testing
Perl TestingPerl Testing
Perl Testing
 
Test in action week 2
Test in action   week 2Test in action   week 2
Test in action week 2
 
Grails/Groovyによる開発事例紹介
Grails/Groovyによる開発事例紹介Grails/Groovyによる開発事例紹介
Grails/Groovyによる開発事例紹介
 
The Ring programming language version 1.6 book - Part 11 of 189
The Ring programming language version 1.6 book - Part 11 of 189The Ring programming language version 1.6 book - Part 11 of 189
The Ring programming language version 1.6 book - Part 11 of 189
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoin
 
Java custom annotations example
Java custom annotations exampleJava custom annotations example
Java custom annotations example
 
The Ring programming language version 1.7 book - Part 12 of 196
The Ring programming language version 1.7 book - Part 12 of 196The Ring programming language version 1.7 book - Part 12 of 196
The Ring programming language version 1.7 book - Part 12 of 196
 
Phpunit testing
Phpunit testingPhpunit testing
Phpunit testing
 
srgoc
srgocsrgoc
srgoc
 
Automated Testing with CMake, CTest and CDash
Automated Testing with CMake, CTest and CDashAutomated Testing with CMake, CTest and CDash
Automated Testing with CMake, CTest and CDash
 
Selenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalks
Selenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalksSelenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalks
Selenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalks
 
Clojure - A new Lisp
Clojure - A new LispClojure - A new Lisp
Clojure - A new Lisp
 
NIO and NIO2
NIO and NIO2NIO and NIO2
NIO and NIO2
 
Testing Django Applications
Testing Django ApplicationsTesting Django Applications
Testing Django Applications
 
JavaOne 2015 - Having fun with Javassist
JavaOne 2015 - Having fun with JavassistJavaOne 2015 - Having fun with Javassist
JavaOne 2015 - Having fun with Javassist
 
The Ring programming language version 1.8 book - Part 87 of 202
The Ring programming language version 1.8 book - Part 87 of 202The Ring programming language version 1.8 book - Part 87 of 202
The Ring programming language version 1.8 book - Part 87 of 202
 
Riga Dev Day 2016 - Having fun with Javassist
Riga Dev Day 2016 - Having fun with JavassistRiga Dev Day 2016 - Having fun with Javassist
Riga Dev Day 2016 - Having fun with Javassist
 
NIO.2, the I/O API for the future
NIO.2, the I/O API for the futureNIO.2, the I/O API for the future
NIO.2, the I/O API for the future
 

Similar a Intro to Testing in Zope, Plone

Unit Testing using PHPUnit
Unit Testing using  PHPUnitUnit Testing using  PHPUnit
Unit Testing using PHPUnit
varuntaliyan
 
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnit
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnitinternational PHP2011_Bastian Feder_The most unknown Parts of PHPUnit
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnit
smueller_sandsmedia
 

Similar a Intro to Testing in Zope, Plone (20)

Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit Testing
 
3 j unit
3 j unit3 j unit
3 j unit
 
Mxunit
MxunitMxunit
Mxunit
 
Practical Glusto Example
Practical Glusto ExamplePractical Glusto Example
Practical Glusto Example
 
Testing My Patience
Testing My PatienceTesting My Patience
Testing My Patience
 
Presto Testing Tools: Benchto & Tempto (Presto Boston Meetup 10062015)
Presto Testing Tools: Benchto & Tempto (Presto Boston Meetup 10062015)Presto Testing Tools: Benchto & Tempto (Presto Boston Meetup 10062015)
Presto Testing Tools: Benchto & Tempto (Presto Boston Meetup 10062015)
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
Pragmatic unittestingwithj unit
Pragmatic unittestingwithj unitPragmatic unittestingwithj unit
Pragmatic unittestingwithj unit
 
using python module: doctest
using python module: doctestusing python module: doctest
using python module: doctest
 
Unit Testing using PHPUnit
Unit Testing using  PHPUnitUnit Testing using  PHPUnit
Unit Testing using PHPUnit
 
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownparts
 
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnit
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnitinternational PHP2011_Bastian Feder_The most unknown Parts of PHPUnit
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnit
 
Android Automated Testing
Android Automated TestingAndroid Automated Testing
Android Automated Testing
 
Fighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitFighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnit
 
New Features Of Test Unit 2.x
New Features Of Test Unit 2.xNew Features Of Test Unit 2.x
New Features Of Test Unit 2.x
 
Scala test
Scala testScala test
Scala test
 
Scala test
Scala testScala test
Scala test
 
Isolated development in python
Isolated development in pythonIsolated development in python
Isolated development in python
 
Junit_.pptx
Junit_.pptxJunit_.pptx
Junit_.pptx
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdf
 

Más de Quintagroup

Plone 4. Що нового?
Plone 4. Що нового?Plone 4. Що нового?
Plone 4. Що нового?
Quintagroup
 
Plone в урядових проектах
Plone в урядових проектахPlone в урядових проектах
Plone в урядових проектах
Quintagroup
 

Más de Quintagroup (20)

Georgian OCDS API
Georgian OCDS APIGeorgian OCDS API
Georgian OCDS API
 
Open procurement - Auction module
Open procurement - Auction moduleOpen procurement - Auction module
Open procurement - Auction module
 
OpenProcurement toolkit
OpenProcurement toolkitOpenProcurement toolkit
OpenProcurement toolkit
 
Open procurement italian
Open procurement italian Open procurement italian
Open procurement italian
 
Plone SEO: Пошукова оптимізація Плон сайтів
Plone SEO: Пошукова оптимізація Плон сайтівPlone SEO: Пошукова оптимізація Плон сайтів
Plone SEO: Пошукова оптимізація Плон сайтів
 
Plone 4. Що нового?
Plone 4. Що нового?Plone 4. Що нового?
Plone 4. Що нового?
 
Calendar for Plone
Calendar for Plone Calendar for Plone
Calendar for Plone
 
Packages, Releases, QGSkel
Packages, Releases, QGSkelPackages, Releases, QGSkel
Packages, Releases, QGSkel
 
Integrator Series: Large files
Integrator Series: Large filesIntegrator Series: Large files
Integrator Series: Large files
 
Python Objects
Python ObjectsPython Objects
Python Objects
 
Python Evolution
Python EvolutionPython Evolution
Python Evolution
 
Screen Player
Screen PlayerScreen Player
Screen Player
 
GNU Screen
GNU ScreenGNU Screen
GNU Screen
 
New in Plone 3.3. What to expect from Plone 4
New in Plone 3.3. What to expect from Plone 4New in Plone 3.3. What to expect from Plone 4
New in Plone 3.3. What to expect from Plone 4
 
Overview of Plone-based websites for mobile devices.
Overview of Plone-based websites for mobile devices.Overview of Plone-based websites for mobile devices.
Overview of Plone-based websites for mobile devices.
 
Ecommerce Solutions for Plone
Ecommerce Solutions for PloneEcommerce Solutions for Plone
Ecommerce Solutions for Plone
 
Templating In Buildout
Templating In BuildoutTemplating In Buildout
Templating In Buildout
 
Releasing and deploying python tools
Releasing and deploying python toolsReleasing and deploying python tools
Releasing and deploying python tools
 
Zope 3 at Google App Engine
Zope 3 at Google App EngineZope 3 at Google App Engine
Zope 3 at Google App Engine
 
Plone в урядових проектах
Plone в урядових проектахPlone в урядових проектах
Plone в урядових проектах
 

Ú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@
 

Último (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
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...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
+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...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 

Intro to Testing in Zope, Plone

  • 1. Intro to Testing in Zope, Plone Andriy Mylenkyy © Quintagroup, 2008
  • 2.
  • 3.
  • 4.
  • 5. unittest.py TestSuite TestCase TC TC TC TestSuite(TS)
  • 6.
  • 7.
  • 8.
  • 9. unittest: TestSuite / TestCase import unittest as ut class WidgetTC(ut.TestCase): def setUp(self): ... def tearDown(self): ... def testDefaultSize(self): assertEqual(...) def testResize(self): self.failIf(...) def otherTest(self): self.assertRaises(...) if __name__ == '__main__': # 1 # ut.main() #1b# ut.main(defaultTest='WidgetTC') #2,3# suite = ut.TestSuite() # 2 # suite.addTest(ut.makeSuite(WidgetTC)) # 3 # suite.addTest('WidgetTC('otherTest')) #2,3# runner = ut.TextTestRunner() #2,3# runner.run(sute) TestSuite _tests WidgetTC("testDefaultSize") WidgetTC("testResize") unittest.makeSuite(WidgetTC)
  • 10. unittest: command line mytest.py ---------------------------------------------- import unittest class WidgetTC(unittest.TestCase): ... if __name__ == '__main__': unittest.main() ----------------------------------------------- $ python mytest.py .. OK ------------------------------------------------- $ python mytest.py WidgetTC.testDefaultSize WidgetTC.testResize .. OK ------------------------------------------------- $ python mytest.py -v testDefaultSize (__main__.WidgetTC) ... ok testResize (__main__.WidgetTC) ... ok ... OK
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16. doctest: Internal structure object DocTes t Example Example Example result DocTestFinder DocTestRunner
  • 17.
  • 18.
  • 19. zope.testing: Lyaers (cont) class BaseLayer : @classmethod def setUp (cls): “ Layer setup ” @classmethod def tearDown (cls): “ Layer teardown ” @classmethod def testSetUp (cls): “ Before each test setup ” @classmethod def testTearDown (cls): “ After each test teardown ” class MyTestCase(TestCase): layer = NestedLayer def setUp(self): pass def tearDown(self): pass class NestedLayer( BaseLayer) : @classmethod def setUp (cls): “ Layer setup ” @classmethod def tearDown (cls): “ Layer teardown ” testrunner.py --path', directory_with_tests --layer 112 --layer Unit'.split
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28. ZTC: Entrypoints setUp(self) try: self. beforeSetUp() self.app = self._app() self._setup() self. afterSetUp() except: self._clear() raise tearDown(self) try: self. beforeTearDown() self._clear(1) except: self._clear() raise Before ALL ZTC Folder, UserFolder, User, login After Fixture created ConnectionRegistry Before delete folder from self.app After folder delete Before close connection to ZODB beforeClose() afterClear() After ALL Zope.APP Opens a ZODB connection Request.__of__(app)
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36. PTC: PloneTestCase example import os, sys if __name__ == '__main__': execfile(os.path.join(sys.path[0], 'framework.py')) from Products.PloneTestCase import PloneTestCase PloneTestCase.setupPloneSite() class TestDocument(PloneTestCase.PloneTestCase): def afterSetUp(self): ... def testAddDocument(self): self.failUnless(...) def test_suite(): ... return suite if __name__ == '__main__': framework()
  • 37.