UPC Plone Testing Talk
-
Upload
plone-foundation -
Category
Technology
-
view
722 -
download
0
Transcript of UPC Plone Testing Talk
![Page 1: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/1.jpg)
Testing for fun and profit
March, 11th 2010
Timo Stollenwerk
![Page 2: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/2.jpg)
Are you still testing manually?
● Are you testing the applications you write?● You are already testing, but in an inefficient
way!● Manual testing is boring and inefficient!● Automated testing makes development more
effective and more fun!
![Page 3: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/3.jpg)
Create a new Plone content type
![Page 4: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/4.jpg)
Start Zope
![Page 5: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/5.jpg)
Create Plone Site
![Page 6: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/6.jpg)
Install Product
![Page 7: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/7.jpg)
Test Adding Manually
![Page 8: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/8.jpg)
Error!
![Page 9: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/9.jpg)
Test View Manually
![Page 10: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/10.jpg)
What sucks about this process?
● You have to create/start/install/test your product over and over again
● You have to write the entire code before you can test it
● You end up with a lot of errors and you don't really know what is causing it
● Manual testing is slow and error-prone!● Repetitive tasks are boring!
![Page 11: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/11.jpg)
Development Process Improvement
● Automate the entire process● Write tests that can tell you what exactly went
wrong● Fixing lots of small pieces of code mean lots of
small successes● Prove that your code does what it is supposed
to do● Make development more fun!
![Page 12: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/12.jpg)
What Do We Want To Test?
● Schema● Factory Type Information● Factory● Adding● View● ...
![Page 13: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/13.jpg)
Create Schema
![Page 14: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/14.jpg)
Test Schema
![Page 15: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/15.jpg)
Run your tests
![Page 16: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/16.jpg)
Create Content Type
![Page 17: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/17.jpg)
Test Factory Type Information
![Page 18: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/18.jpg)
Test Factory
![Page 19: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/19.jpg)
Error!
![Page 20: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/20.jpg)
Test Adding
![Page 21: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/21.jpg)
Test View
![Page 22: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/22.jpg)
Why Testing Matters
● Testing reduces defects as measured by reported bugs
● Finding bugs early makes them cheaper to fix● Tests passing is proof that you delivered what
you were contracted to produce● Refactor with confidence● Lot of small steps means lot of small successes
![Page 23: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/23.jpg)
Testing Pyramid
![Page 24: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/24.jpg)
Functional Testing
● Blackbox testing● Automated acceptance testing
![Page 25: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/25.jpg)
XP/Scrum and Functional Testing
● Testing started as part of XP● Acceptance tests can map directly to your software
requirements
● XP/Scrum:● Write testable specifications● Write code that complies with the specification and
tests● Use the testable specification to prove that your
application is doing what it is supposed to do
![Page 26: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/26.jpg)
Telling User Stories with Doctests
As a logged-in user, I can add a new Task to the website.
![Page 27: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/27.jpg)
Doctest Example
![Page 28: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/28.jpg)
Unit Tests in Plone
![Page 29: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/29.jpg)
Unit Testing
CODE:
def is_palindrome(input_str): pass
TEST:
def test_palindromic_word(): input = "noon" assert is_palindrome(input) == True
![Page 30: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/30.jpg)
Testing one unit at a time
● Usually you have to set up some components in order to test a Unit
● But how?
![Page 31: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/31.jpg)
Mock And Fake Objects
● Unittest code that has external dependencies● Plone components● External databases● Network connections
● Depends on external components
![Page 32: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/32.jpg)
Mock Testing Example
![Page 33: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/33.jpg)
Test Driven Development
● Write a testable specification● Write integration tests● Write Unit Tests● Write code that complies with the specification
and tests● Use the testable specification and unit tests to
help debug/refactor
![Page 34: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/34.jpg)
More Testing Topics
● Code Coverage● Twill● Selenium● zope.testrecorder● Continuous Integration● IDE Integration
![Page 35: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/35.jpg)
Code Resources
● Code for this talk upc.testingtutorial● https://devel.upcnet.es/svn/upcnet/upc.testingtutorial/
● UPC Deploymentmanager● https://devel.upcnet.es/svn/upcnet/upc.deploymentmanager/
● Recent Activity Portlet● http://pypi.python.org/pypi/collective.portlet.recentactivity
● plone.app.discussion● http://pypi.python.org/pypi/plone.app.discussion
![Page 36: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/36.jpg)
Testing Resources
● Plone Testing Tutorial● http://plone.org/documentation/kb/testing
● Plone 3 / Archetypes ● PPD / Optilux
● Plone 4 / Dexterity Dev Manual● http://plone.org/products/dexterity/documentation/manual/developer-manual● Example Package:
http://svn.plone.org/svn/collective/example.conference/
![Page 37: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/37.jpg)
Books about Testing
● Kent Beck: Test Driven Development● http://www.amazon.com/Test-Driven-Development-Kent-Beck/dp/0321146530
● Python Testing: Beginner's Guide● http://www.packtpub.com/python-testing-beginners-guide/book
● Tarek Ziadé: Expert Python Programming● http://www.amazon.com/Expert-Python-
Programming-practices-distributing/dp/184719494X/ref=sr_1_1?ie=UTF8&s=books&qid=1268299804&sr=1-1-spell
![Page 38: UPC Plone Testing Talk](https://reader036.fdocuments.net/reader036/viewer/2022062319/554bc0f3b4c90594278b514c/html5/thumbnails/38.jpg)
The End