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

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

Quality of life through Unit Testing
Quality of life through Unit TestingQuality of life through Unit Testing
Quality of life through Unit TestingSian Lerk Lau
 
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 discoveringromanovfedor
 
Unit testing framework
Unit testing frameworkUnit testing framework
Unit testing frameworkIgor Vavrish
 
Testing with JUnit 5 and Spring
Testing with JUnit 5 and SpringTesting with JUnit 5 and Spring
Testing with JUnit 5 and SpringVMware Tanzu
 
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 2016Dusan Lukic
 
Testing Django APIs
Testing Django APIsTesting Django APIs
Testing Django APIstyomo4ka
 
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 Suiteericholscher
 
Unit Testing Frameworks: A comparative study
Unit Testing Frameworks: A comparative studyUnit Testing Frameworks: A comparative study
Unit Testing Frameworks: A comparative studyIRJET Journal
 
Integration Group - Robot Framework
Integration Group - Robot Framework Integration Group - Robot Framework
Integration Group - Robot Framework OpenDaylight
 
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 Inexture Solutions
 
JS Lab2017_Андрей Кучеренко _Разработка мультипакетных приложения: причины, с...
JS Lab2017_Андрей Кучеренко _Разработка мультипакетных приложения: причины, с...JS Lab2017_Андрей Кучеренко _Разработка мультипакетных приложения: причины, с...
JS Lab2017_Андрей Кучеренко _Разработка мультипакетных приложения: причины, с...GeeksLab Odessa
 
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-testkit7mind
 
Performance testing and j meter
Performance testing and j meterPerformance testing and j meter
Performance testing and j meterPurna Chandar
 
Test Driven Development with Sql Server
Test Driven Development with Sql ServerTest Driven Development with Sql Server
Test Driven Development with Sql ServerDavid P. Moore
 
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 FrameworksDimitry Polivaev
 
Qtp framework implementation_guide_v1
Qtp framework implementation_guide_v1Qtp framework implementation_guide_v1
Qtp framework implementation_guide_v1Saurabh 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

Communications Between Tribes
Communications Between TribesCommunications Between Tribes
Communications Between TribesGareth Rushgrove
 
The Challenges of Container Configuration
The Challenges of Container ConfigurationThe Challenges of Container Configuration
The Challenges of Container ConfigurationGareth Rushgrove
 
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 ElseGareth Rushgrove
 
Config managament for development environments ii
Config managament for development environments iiConfig managament for development environments ii
Config managament for development environments iiGareth Rushgrove
 
Vagrant and Configuration Management
Vagrant and Configuration ManagementVagrant and Configuration Management
Vagrant and Configuration ManagementGareth Rushgrove
 
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 ToolboxGareth Rushgrove
 
Automating web site deployment
Automating web site deploymentAutomating web site deployment
Automating web site deploymentGareth Rushgrove
 
Message Queues for Web Applications
Message Queues for Web ApplicationsMessage Queues for Web Applications
Message Queues for Web ApplicationsGareth Rushgrove
 
Beyond basic web development
Beyond basic web developmentBeyond basic web development
Beyond basic web developmentGareth Rushgrove
 
Self Education for Web Professionals
Self Education for Web ProfessionalsSelf Education for Web Professionals
Self Education for Web ProfessionalsGareth Rushgrove
 
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 EngineGareth Rushgrove
 
App Engine for Python Developers
App Engine for Python DevelopersApp Engine for Python Developers
App Engine for Python DevelopersGareth 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

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
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.pdfsudhanshuwaghmare1
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
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, ...apidays
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
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 TerraformAndrey Devyatkin
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 

Recently uploaded (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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, ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

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