What is Django testing?
Why Interviewers Ask This
This tests whether you can apply Django knowledge to real-world scenarios. Interviewers are looking for clarity of thought and evidence that you've encountered this in production code.
Answer
Django's testing framework extends Python's unittest with Django-specific tools: TestCase classes: from django.test import TestCase, Client, RequestFactory class ArticleViewTest(TestCase): def setUp(self): self.user = User.objects.create_user("alice", "alice@example.com", "pass123") self.client = Client() self.client.login(username="alice", password="pass123") self.article = Article.objects.create(title="Test", content="Content", author=self.user) def test_article_list(self): response = self.client.get("/articles/") self.assertEqual(response.status_code, 200) self.assertContains(response, "Test") self.assertTemplateUsed(response, "articles/list.html") def test_create_article(self): response = self.client.post("/articles/create/", {"title": "New", "content": "Body"}) self.assertEqual(response.status_code, 302) # redirect on success self.assertEqual(Article.objects.count(), 2) def test_unauthorized_delete(self): other_user = User.objects.create_user("bob", password="pass") self.client.login(username="bob", password="pass") response = self.client.delete(f"/articles/{self.article.pk}/delete/") self.assertEqual(response.status_code, 403). DRF testing: from rest_framework.test import APITestCase, APIClient class UserAPITest(APITestCase): def test_create_user(self): data = {"username": "alice", "email": "a@a.com", "password": "pass123"} response = self.client.post("/api/users/", data, format="json") self.assertEqual(response.status_code, 201). Factories: use factory_boy for test data: class ArticleFactory(factory.django.DjangoModelFactory): class Meta: model = Article title = factory.Sequence(lambda n: f"Article {n}"). Fixtures vs Factories: factories are preferred — more maintainable. python manage.py test --verbosity=2 --keepdb.
Pro Tip
Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a Django codebase.