SlideShare a Scribd company logo
1 of 21
Download to read offline
..............................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 | morethanseven.net
Not Simon Willison


gareth rushgrove | morethanseven.net
Not Simon Willison Gareth Rushgrove


gareth rushgrove | morethanseven.net
Who Writes Tests? Own Up.


gareth rushgrove | morethanseven.net
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 | morethanseven.net
                                             A test suite is a collection of test cases, test suites, or both. It is used
...F................E.



Pass, Fail, Error


gareth rushgrove | morethanseven.net
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 manage.py utility:

 $ ./manage.py 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:

 $ ./manage.py 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:

 $ ./manage.py 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:

 $ ./manage.py test animals.AnimalTestCase.testFluffyAnimals


The test database
gareth rushgrove | morethanseven.net
What to Test - Low Level Code


gareth rushgrove | morethanseven.net
- Functions
       - Input/output
       - Object methods
       - Object creation
       - Action at a distance via signals




Unit Tests and System Tests


gareth rushgrove | morethanseven.net
What to Test - High Level Code


gareth rushgrove | morethanseven.net
- 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 | morethanseven.net
Past the Basics


gareth rushgrove | morethanseven.net
Custom Assertions


gareth rushgrove | morethanseven.net
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://github.com/garethr/django-test-extensions.git
 Your Clone URL:     git@github.com:garethr/django-test-extensions.git


                                                                                                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]

    setup.py           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 | morethanseven.net
Custom Test Runner


gareth rushgrove | morethanseven.net
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 | morethanseven.net
Tools Integration


gareth rushgrove | morethanseven.net
Unit                 System   Functional   Integration


Separate Test Suites


gareth rushgrove | morethanseven.net
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 | morethanseven.net
http://flickr.com/photos/psd/102332391/

       http://flickr.com/photos/ijames/112866961/

   http://flickr.com/photos/venancio2007/3059620452/

 http://flickr.com/photos/bigdogwoody2000/2540302958/

       http://flickr.com/photos/pigatto/333486434/



Flickr Credits
Go Forth And Write Tests


gareth rushgrove | morethanseven.net

More Related Content

What's hot

Advanced junit and mockito
Advanced junit and mockitoAdvanced junit and mockito
Advanced junit and mockito
Mathieu Carbou
 
TestNG introduction
TestNG introductionTestNG introduction
TestNG introduction
Denis Bazhin
 
New and improved: Coming changes to the unittest module
 	 New and improved: Coming changes to the unittest module 	 New and improved: Coming changes to the unittest module
New and improved: Coming changes to the unittest module
PyCon Italia
 

What's hot (20)

ssssssssss
ssssssssssssssssssss
ssssssssss
 
Advanced junit and mockito
Advanced junit and mockitoAdvanced junit and mockito
Advanced junit and mockito
 
Junit
JunitJunit
Junit
 
Intro to Testing in Zope, Plone
Intro to Testing in Zope, PloneIntro to Testing in Zope, Plone
Intro to Testing in Zope, Plone
 
Junit
JunitJunit
Junit
 
TestNG vs. JUnit4
TestNG vs. JUnit4TestNG vs. JUnit4
TestNG vs. JUnit4
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
Introduction to JUnit
Introduction to JUnitIntroduction to JUnit
Introduction to JUnit
 
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and MockitoAn Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
 
TestNG
TestNGTestNG
TestNG
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
Junit4&testng presentation
Junit4&testng presentationJunit4&testng presentation
Junit4&testng presentation
 
JUNit Presentation
JUNit PresentationJUNit Presentation
JUNit Presentation
 
Simple Unit Testing With Netbeans 6.1
Simple Unit Testing With Netbeans 6.1Simple Unit Testing With Netbeans 6.1
Simple Unit Testing With Netbeans 6.1
 
TestNG introduction
TestNG introductionTestNG introduction
TestNG introduction
 
ikp321-04
ikp321-04ikp321-04
ikp321-04
 
Junit
JunitJunit
Junit
 
JUnit 5 - The Next Generation
JUnit 5 - The Next GenerationJUnit 5 - The Next Generation
JUnit 5 - The Next Generation
 
New and improved: Coming changes to the unittest module
 	 New and improved: Coming changes to the unittest module 	 New and improved: Coming changes to the unittest module
New and improved: Coming changes to the unittest module
 
Testing Spring Applications
Testing Spring ApplicationsTesting Spring Applications
Testing Spring Applications
 

Similar to Testing Django Applications

Making the most of your Test Suite
Making the most of your Test SuiteMaking the most of your Test Suite
Making the most of your Test Suite
ericholscher
 
Strategy-driven Test Generation with Open Source Frameworks
Strategy-driven Test Generation with Open Source FrameworksStrategy-driven Test Generation with Open Source Frameworks
Strategy-driven Test Generation with Open Source Frameworks
Dimitry Polivaev
 
Qtp framework implementation_guide_v1
Qtp framework implementation_guide_v1Qtp framework implementation_guide_v1
Qtp framework implementation_guide_v1
Saurabh Singh
 

Similar to Testing Django Applications (20)

Quality of life through Unit Testing
Quality of life through Unit TestingQuality of life through Unit Testing
Quality of life through Unit Testing
 
S313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discoveringS313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discovering
 
Unit testing framework
Unit testing frameworkUnit testing framework
Unit testing framework
 
Testing with JUnit 5 and Spring
Testing with JUnit 5 and SpringTesting with JUnit 5 and Spring
Testing with JUnit 5 and Spring
 
Introduction to clarity
Introduction to clarityIntroduction to clarity
Introduction to clarity
 
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
 
Testing Django APIs
Testing Django APIsTesting Django APIs
Testing Django APIs
 
Making the most of your Test Suite
Making the most of your Test SuiteMaking the most of your Test Suite
Making the most of your Test Suite
 
Unit Testing Frameworks: A comparative study
Unit Testing Frameworks: A comparative studyUnit Testing Frameworks: A comparative study
Unit Testing Frameworks: A comparative study
 
Integration Group - Robot Framework
Integration Group - Robot Framework Integration Group - Robot Framework
Integration Group - Robot Framework
 
Mini training - Moving to xUnit.net
Mini training - Moving to xUnit.netMini training - Moving to xUnit.net
Mini training - Moving to xUnit.net
 
DIY in 5 Minutes: Testing Django App with Pytest
DIY in 5 Minutes: Testing Django App with Pytest DIY in 5 Minutes: Testing Django App with Pytest
DIY in 5 Minutes: Testing Django App with Pytest
 
JS Lab2017_Андрей Кучеренко _Разработка мультипакетных приложения: причины, с...
JS Lab2017_Андрей Кучеренко _Разработка мультипакетных приложения: причины, с...JS Lab2017_Андрей Кучеренко _Разработка мультипакетных приложения: причины, с...
JS Lab2017_Андрей Кучеренко _Разработка мультипакетных приложения: причины, с...
 
Gallio Crafting A Toolchain
Gallio Crafting A ToolchainGallio Crafting A Toolchain
Gallio Crafting A Toolchain
 
Hyper-pragmatic Pure FP testing with distage-testkit
Hyper-pragmatic Pure FP testing with distage-testkitHyper-pragmatic Pure FP testing with distage-testkit
Hyper-pragmatic Pure FP testing with distage-testkit
 
Performance testing and j meter
Performance testing and j meterPerformance testing and j meter
Performance testing and j meter
 
Test ng for testers
Test ng for testersTest ng for testers
Test ng for testers
 
Test Driven Development with Sql Server
Test Driven Development with Sql ServerTest Driven Development with Sql Server
Test Driven Development with Sql Server
 
Strategy-driven Test Generation with Open Source Frameworks
Strategy-driven Test Generation with Open Source FrameworksStrategy-driven Test Generation with Open Source Frameworks
Strategy-driven Test Generation with Open Source Frameworks
 
Qtp framework implementation_guide_v1
Qtp framework implementation_guide_v1Qtp framework implementation_guide_v1
Qtp framework implementation_guide_v1
 

More from Gareth Rushgrove

More from Gareth Rushgrove (20)

Communications Between Tribes
Communications Between TribesCommunications Between Tribes
Communications Between Tribes
 
The Challenges of Container Configuration
The Challenges of Container ConfigurationThe Challenges of Container Configuration
The Challenges of Container Configuration
 
Puppet and Openshift
Puppet and OpenshiftPuppet and Openshift
Puppet and Openshift
 
Two Sides of Google Infrastructure for Everyone Else
Two Sides of Google Infrastructure for Everyone ElseTwo Sides of Google Infrastructure for Everyone Else
Two Sides of Google Infrastructure for Everyone Else
 
Thinking Evil Thoughts
Thinking Evil ThoughtsThinking Evil Thoughts
Thinking Evil Thoughts
 
Puppet Data Mining
Puppet Data MiningPuppet Data Mining
Puppet Data Mining
 
Web operations
Web operationsWeb operations
Web operations
 
Learnings from govuk
Learnings from govukLearnings from govuk
Learnings from govuk
 
Config managament for development environments ii
Config managament for development environments iiConfig managament for development environments ii
Config managament for development environments ii
 
Varnish Caching
Varnish CachingVarnish Caching
Varnish Caching
 
Vagrant and Configuration Management
Vagrant and Configuration ManagementVagrant and Configuration Management
Vagrant and Configuration Management
 
Metrics with Ganglia
Metrics with GangliaMetrics with Ganglia
Metrics with Ganglia
 
You're Going To Need A Bigger Toolbox
You're Going To Need A Bigger ToolboxYou're Going To Need A Bigger Toolbox
You're Going To Need A Bigger Toolbox
 
Devops
DevopsDevops
Devops
 
Automating web site deployment
Automating web site deploymentAutomating web site deployment
Automating web site deployment
 
Message Queues for Web Applications
Message Queues for Web ApplicationsMessage Queues for Web Applications
Message Queues for Web Applications
 
Beyond basic web development
Beyond basic web developmentBeyond basic web development
Beyond basic web development
 
Self Education for Web Professionals
Self Education for Web ProfessionalsSelf Education for Web Professionals
Self Education for Web Professionals
 
What to Build with Google App Engine
What to Build with Google App EngineWhat to Build with Google App Engine
What to Build with Google App Engine
 
App Engine for Python Developers
App Engine for Python DevelopersApp Engine for Python Developers
App Engine for Python Developers
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+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@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
+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...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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
 

Testing Django Applications

  • 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 | morethanseven.net
  • 2. Not Simon Willison gareth rushgrove | morethanseven.net
  • 3. Not Simon Willison Gareth Rushgrove gareth rushgrove | morethanseven.net
  • 4. Who Writes Tests? Own Up. gareth rushgrove | morethanseven.net
  • 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 | morethanseven.net A test suite is a collection of test cases, test suites, or both. It is used
  • 6. ...F................E. Pass, Fail, Error gareth rushgrove | morethanseven.net
  • 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 manage.py utility: $ ./manage.py 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: $ ./manage.py 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: $ ./manage.py 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: $ ./manage.py test animals.AnimalTestCase.testFluffyAnimals The test database gareth rushgrove | morethanseven.net
  • 8. What to Test - Low Level Code gareth rushgrove | morethanseven.net
  • 9. - Functions - Input/output - Object methods - Object creation - Action at a distance via signals Unit Tests and System Tests gareth rushgrove | morethanseven.net
  • 10. What to Test - High Level Code gareth rushgrove | morethanseven.net
  • 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 | morethanseven.net
  • 12. Past the Basics gareth rushgrove | morethanseven.net
  • 13. Custom Assertions gareth rushgrove | morethanseven.net
  • 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://github.com/garethr/django-test-extensions.git Your Clone URL: git@github.com:garethr/django-test-extensions.git 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] setup.py 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 | morethanseven.net
  • 15. Custom Test Runner gareth rushgrove | morethanseven.net
  • 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 | morethanseven.net
  • 17. Tools Integration gareth rushgrove | morethanseven.net
  • 18. Unit System Functional Integration Separate Test Suites gareth rushgrove | morethanseven.net
  • 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 | morethanseven.net
  • 20. http://flickr.com/photos/psd/102332391/ http://flickr.com/photos/ijames/112866961/ http://flickr.com/photos/venancio2007/3059620452/ http://flickr.com/photos/bigdogwoody2000/2540302958/ http://flickr.com/photos/pigatto/333486434/ Flickr Credits
  • 21. Go Forth And Write Tests gareth rushgrove | morethanseven.net