TDD in the Web with Python and Django

3,102 views

Published on

My talk in the XP2011 conference in Madrid :-) Thanks to the XP2011 staff !!!

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,102
On SlideShare
0
From Embeds
0
Number of Embeds
1,008
Actions
Shares
0
Downloads
35
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

TDD in the Web with Python and Django

  1. 1. TDD in the Web with Python XP Conference 2011 Carlos Blé www.carlosble.com @carlosble
  2. 2. The Architecture Ruby on Rails, Django , Monorail, ASP.Net MVC, Spring MVC, Play Framework, Symphony, Zend Framework...
  3. 3. We like to think like this
  4. 4. Separate concerns Controller : Deals with the browser . Get the input, make some calls and return the output . It should be as simple as possible. The less it knows about the domain, the better. View : Renders UI. Doesn't know the domain at all!!! Domain : Deals with the user . Business requirements. Wouldn't be cool if we can exercise the domain using ”end-to-end” tests?
  5. 5. Test-driving Inside-out (bottom-up) So we can test-drive the domain and invoke it from the controller after all, like this: Now we can write an integration test for this controller... but integration tests are painful!
  6. 6. Is not that clean always :-(
  7. 7. When the controller needs to know <ul><li>Validation rules
  8. 8. How to parse complex data (forms)
  9. 9. Which UI to render for a given scenario </li></ul>We end up with a mess :-(
  10. 10. Test-driving Outside-in (top-down) Integration tests are a scam. Let's go ” unit” We don't use Django's TestCase, but unittest's
  11. 11. Replacing with test doubles
  12. 12. Replace conditional with polymorphism We can move conditionals from views to controllers
  13. 13. Replace conditional with polymorphism Django templates inheritance is so cool!!!
  14. 14. Conclusions <ul><li>End-to-end tests for the domain, are cheaper excluding web concerns (controllers, UIs)
  15. 15. Selenium (or Webdriver) tests are too fragile
  16. 16. Test-driving controllers give us fast feedback
  17. 17. So we recommend: </li><ul><li>Unit test the controllers (test-first)
  18. 18. Unit test the domain (test-first)
  19. 19. Write integration tests for DB access, etc
  20. 20. Write end-to-end tests for the domain </li></ul></ul>We don't use Django's TestCase, but unittest's

×