Test Case Classes in Django
Beyond the base TestCase
class provided by Django, which can be used to define a multitude of test cases for different components, Django also provides some specialized classes derived from the TestCase
class. These classes are used for specific types of test cases based on the capabilities they provide to the developer.
Let us take a quick look at them.
SimpleTestCase
This class is derived from the TestCase
class provided by Django's test
module and should be used for writing simple test cases that test the view functions. Usually, the class is not preferred when your test case involves making database queries. The class also provides a lot of useful features, such as the following:
- The ability to check for exceptions raised by a view function
- The ability to test form fields
- A built-in test client
- The ability to verify a redirect by a view function
- Matching the equality of two HTML, JSON, or XML outputs generated by...