Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Testing Django with Travis CI

Adam McKerlie
November 11, 2012

Testing Django with Travis CI

A talk I gave on testing Django and using Travis CI for Pycon Canada

Adam McKerlie

November 11, 2012
Tweet

More Decks by Adam McKerlie

Other Decks in Technology

Transcript

  1. • Python Developer at • Twitter: @adammckerlie • Everywhere else:

    silent1mezzo ABOUT ME 2 Sunday, November 11, 12
  2. • Definitions • Why you should test your code •

    What parts of your code you should test • Writing your first test • Integrating Travis CI to automatically run your tests OVERVIEW 4 Sunday, November 11, 12
  3. UNIT TEST • Tests one small section of code •

    Focuses your code • Fast 5 Sunday, November 11, 12
  4. INTEGRATION TEST • Tests that the whole system works (views,

    forms, etc...) • Slow • Gives you a full picture of what’s happening 6 Sunday, November 11, 12
  5. • Gives you confidence in your code • Allows you

    to iterate faster • Provides beginners an easy spot to code-dive • Untested code is expensive WHY YOU SHOULD WRITE TESTS 7 Sunday, November 11, 12
  6. • Don’t test Django or Python’s built-in stuff • Test

    your views, models, forms, management commands, etc... WHAT YOU SHOULD TEST 9 Sunday, November 11, 12
  7. • Tests can go in models.py or tests.py • Must

    subclass django.test.TestCase • python manage.py test <app_name> WRITING YOUR FIRST TEST 10 Sunday, November 11, 12
  8. • Fixtures are serialized data that you can load. •

    python manage.py dumpdata app_name > app_name/fixtures/file.json USING FIXTURES 12 Sunday, November 11, 12
  9. • After every commit • Before you merge your branches

    into master • Once you’ve deployed your code WHEN SHOULD YOU TEST 14 Sunday, November 11, 12
  10. WHAT IS TRAVIS-CI? • Continuous Integration Testing • Open Source

    • https://github.com/travis-ci 15 Sunday, November 11, 12
  11. HOW DOES IT WORK? • Sign up with your github

    account • Specify repositories • Include a .travis.yml file • Change/commit/push code • Tests run automagically 17 Sunday, November 11, 12
  12. PULL REQUESTS • Test Pull Requests before they’re merged to

    master • Notifications of running tests • Notifications of successful tests 22 Sunday, November 11, 12