Book Image

Learning Website Development with Django

Book Image

Learning Website Development with Django

Overview of this book

Table of Contents (18 chapters)
Learning Website Development with Django
Credits
About the Author
About the Reviewers
Preface
Index

Unit Testing


During the course of this book, we sometimes had to modify a view that we wrote previously. This actually happens quite often while developing software. One may modify or even rewrite a function to change implementation details, or because the requirements have changed, or simply to re-factor the code and make it more readable.

When you modify a function, you have to test it again to make sure that your changes didn't introduce bugs. However, testing will become a boring task if you have to repeat the same tests over and over every time you modify a function. You may also forget to test all aspects of the function if they are not well documented. Clearly, this is not an ideal situation; we definitely need a better mechanism to handle testing.

Fortunately, a solution already exists for this. It is called unit testing. The idea is that you write code to test your code. The testing code calls your functions and verifies that they behave as expected, and then prints a report of the...