Your SlideShare is downloading. ×
  • Like
Testing Django Applications
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Testing Django Applications


Quick introduction to testing django applications. Given at the January meeting of DJUGL in London.

Quick introduction to testing django applications. Given at the January meeting of DJUGL in London.

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • Nice Presentation !
    Are you sure you want to
    Your message goes here
No Downloads


Total Views
On SlideShare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 1. ..............................E. ========================================================= ERROR: test_admin_related_links_presence (apps.pages.integration_tests.frontend.FrontendTest) --------------------------------------------------------- Ran 32 tests in 132.851s FAILED (errors=1) Destroying test database... Practical Testing for Django Developers DJUGL 19th January 2008 gareth rushgrove |
  • 2. Not Simon Willison gareth rushgrove |
  • 3. Not Simon Willison Gareth Rushgrove gareth rushgrove |
  • 4. Who Writes Tests? Own Up. gareth rushgrove |
  • 5. Python v2.6.1 documentation » The Python Standard Library » Development Tools » previous | next | modules | index — Unit testing framework Table Of Contents unittest — Unit testing unittest framework New in version 2.1. Basic example Organizing test code The Python unit testing framework, sometimes referred to as “PyUnit,” is a Re-using old test code Python language version of JUnit, by Kent Beck and Erich Gamma. JUnit Classes and functions is, in turn, a Java version of Kent!s Smalltalk testing framework. Each is TestCase Objects TestSuite Objects the de facto standard unit testing framework for its respective language. TestResult Objects TestLoader Objects supports test automation, sharing of setup and shutdown code unittest Previous topic for tests, aggregation of tests into collections, and independence of the tests from the reporting framework. The unittest module provides — Test interactive doctest classes that make it easy to support these qualities for a set of tests. Python examples Next topic To achieve this, supports some important concepts: unittest 2to3 - Automated Python 2 to 3 code translation test fixture A test fixture represents the preparation needed to perform one or This Page more tests, and any associate cleanup actions. This may involve, for Show Source example, creating temporary or proxy databases, directories, or Quick search starting a server process. Testing Python with PyUnit test case Go A test case is the smallest unit of testing. It checks for a specific response to a particular set of inputs. unittest provides a base class, Enter search terms or a module, class or function name. TestCase , which may be used to create new test cases. test suite gareth rushgrove | A test suite is a collection of test cases, test suites, or both. It is used
  • 6. ...F................E. Pass, Fail, Error gareth rushgrove |
  • 7. Again, remember that you can use both systems side-by-side (even in the same app). In the end, most projects will eventually end up using both. Each shines in different circumstances. Running tests Once you've written tests, run them using your project's utility: $ ./ test By default, this will run every test in every application in INSTALLED_APPS. If you only want to run tests for a particular application, add the application name to the command line. For example, if your INSTALLED_APPS contains 'myproject.polls' and 'myproject.animals', you can run the myproject.animals unit tests alone with this command: $ ./ test animals Note that we used animals, not myproject.animals. New in Django 1.0: You can now choose which test to run. If you use unit tests, as opposed to doctests, you can be even more specific in choosing which tests to execute. To run a single test case in an application (for example, the AnimalTestCase described in the quot;Writing unit testsquot; section), add the name of the test case to the label on the command line: $ ./ test animals.AnimalTestCase Django Test Runner And it gets even more granular than that! To run a single test method inside a test case, add the name of the test method to the label: $ ./ test animals.AnimalTestCase.testFluffyAnimals The test database gareth rushgrove |
  • 8. What to Test - Low Level Code gareth rushgrove |
  • 9. - Functions - Input/output - Object methods - Object creation - Action at a distance via signals Unit Tests and System Tests gareth rushgrove |
  • 10. What to Test - High Level Code gareth rushgrove |
  • 11. - HTTP Status codes - Fragments of HTML from templatetags - Broken links - Presence of markup on pages - Rendered HTML - Check admin registration - Functionality Functional Tests gareth rushgrove |
  • 12. Past the Basics gareth rushgrove |
  • 13. Custom Assertions gareth rushgrove |
  • 14. garethr account | profile | guides | log out repositories: all | search 0 Source Commits Graphs Wiki (1) Watchers (1) Network (1) Fork Queue Admin master all branches all tags garethr / django-test-extensions Description: A set of custom assertions and examples for use testing django applications edit Homepage: Click to edit edit Public Clone URL: git:// Your Clone URL: commit c327bac72d990af890c231e33d0e146a79b7c507 refactor into setup tools module and include custom test runners tree 92148ec270467b41cb7d5ef5f194a14b44192d8d garethr (author) parent 85237c52d0afd22eb3c1af1e7d639f21fa5bfde9 November 24, 2008 django-test-extensions / name age message history .gitignore November 24, 2008 refactor into setup tools module and include cu... [garethr] README November 22, 2008 seperated out django assertions and added README [garethr] November 24, 2008 refactor into setup tools module and include cu... [garethr] Common Base Class src/ November 24, 2008 refactor into setup tools module and include cu... [garethr] PyUnit provides a basic set of assertions which can get you started with unit testing python, but it's always useful to have more. Django also has a few specific requirements and common patterns when it comes to testing. This set of classes aims to provide a useful starting point for both these situations. gareth rushgrove |
  • 15. Custom Test Runner gareth rushgrove |
  • 16. Name Stmts Exec Cover ---------------------------------------- __init__ 2 0 0% loader 10 0 0% main 85 56 65% models 5 0 0% settings 2 0 0% ---------------------------------------- TOTAL 104 56 53% Coverage Reporting gareth rushgrove |
  • 17. Tools Integration gareth rushgrove |
  • 18. Unit System Functional Integration Separate Test Suites gareth rushgrove |
  • 19. Ellington’s test suite, which was taking around 1.5-2 hours to run on Postgres, has been reduced to 10 minutes. ericholscher Speed Improvements gareth rushgrove |
  • 20. Flickr Credits
  • 21. Go Forth And Write Tests gareth rushgrove |