Introducing automated testing

What are automated tests?

You have been testing code right throughout this book; maybe without even realizing it. Each time you use the Django shell to see if a function works, or to see what output you get for a given input, you are testing your code. For example, back in Chapter 2, Views and URLconfs, we passed a string to a view that expected an integer to generate a TypeError exception.

Testing is a normal part of application development, however what's different in automated tests is that the testing work is done for you by the system. You create a set of tests once, and then as you make changes to your app, you can check that your code still works as you originally intended, without having to perform time consuming manual testing.

So why create tests?

If creating simple applications like those in this book is the last bit of Django programming you do, then true, you don't need to know how to create automated tests. But, if you wish to become a professional programmer and/or work on more complex projects, you need to know how to create automated tests.

Creating automated tests will:

  • Save you time: Manually testing the myriad complex interactions between components of a big application is time-consuming and error prone. Automated tests save time and let you focus on programming.
  • Prevent problems: Tests highlight the internal workings of your code, so you can see where things have gone wrong.
  • Look professional: The pros write tests. Jacob Kaplan-Moss, one of Django's original developers, says "Code without tests is broken by design."
  • Improve teamwork: Tests guarantee that colleagues don't inadvertently break your code (and that you don't break theirs without knowing).
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset