38
Testing for fun and profit March, 11 th 2010 Timo Stollenwerk

UPC Plone Testing Talk

Embed Size (px)

Citation preview

Page 1: UPC Plone Testing Talk

Testing for fun and profit

March, 11th 2010

Timo Stollenwerk

Page 2: UPC Plone Testing Talk

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

Create a new Plone content type

Page 4: UPC Plone Testing Talk

Start Zope

Page 5: UPC Plone Testing Talk

Create Plone Site

Page 6: UPC Plone Testing Talk

Install Product

Page 7: UPC Plone Testing Talk

Test Adding Manually

Page 8: UPC Plone Testing Talk

Error!

Page 9: UPC Plone Testing Talk

Test View Manually

Page 10: UPC Plone Testing Talk

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

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

What Do We Want To Test?

● Schema● Factory Type Information● Factory● Adding● View● ...

Page 13: UPC Plone Testing Talk

Create Schema

Page 14: UPC Plone Testing Talk

Test Schema

Page 15: UPC Plone Testing Talk

Run your tests

Page 16: UPC Plone Testing Talk

Create Content Type

Page 17: UPC Plone Testing Talk

Test Factory Type Information

Page 18: UPC Plone Testing Talk

Test Factory

Page 19: UPC Plone Testing Talk

Error!

Page 20: UPC Plone Testing Talk

Test Adding

Page 21: UPC Plone Testing Talk

Test View

Page 22: UPC Plone Testing Talk

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

Testing Pyramid

Page 24: UPC Plone Testing Talk

Functional Testing

● Blackbox testing● Automated acceptance testing

Page 25: UPC Plone Testing Talk

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

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

Doctest Example

Page 28: UPC Plone Testing Talk

Unit Tests in Plone

Page 29: UPC Plone Testing Talk

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

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

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

Mock Testing Example

Page 33: UPC Plone Testing Talk

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

More Testing Topics

● Code Coverage● Twill● Selenium● zope.testrecorder● Continuous Integration● IDE Integration

Page 35: UPC Plone Testing Talk

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

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

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

The End