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’s look at the different classes provided by Django.
The SimpleTestCase class
This class is derived from the TestCase
class provided by Django’s test
module and should be used when writing simple test cases that test the view functions. Usually, this class is not preferred when your test case involves making database queries. The class also provides a lot of useful features, such as these:
- Ability to check for exceptions raised by a view function
- Ability to test form fields
- A built-in test client
- Ability to verify a redirect by a view function
- Can match the equality of two HTML, JSON, or...