Django

Django Testing

TestCase, test fixtures, factories, test client, coverage, TDD, mocking, CI/CD integration

22 면접 질문·
Mid-Level
1

Which base class should be used to write unit tests in Django?

답변

django.test.TestCase is the recommended base class for Django unit tests. It inherits from unittest.TestCase and adds Django-specific features like automatic wrapping of tests in a database transaction that gets rolled back after each test, ensuring test isolation.

2

What is the main difference between TestCase and TransactionTestCase in Django?

답변

TestCase wraps tests in an atomic transaction that is rolled back at the end, which is faster but prevents testing real transactional behaviors. TransactionTestCase recreates the database between each test, allowing testing of explicit commits and rollbacks, but is slower.

3

How to use the Django test client to simulate a GET request to a view?

답변

The Django test client, accessible via self.client in a TestCase, allows simulating HTTP requests. The method self.client.get('/url/') simulates a GET request and returns a Response object containing the status_code, content and template context used for rendering.

4

How to load predefined test data in Django using JSON fixtures?

5

What is the main advantage of using Factory Boy over JSON fixtures?

+19 면접 질문

다음 면접을 위해 Django을 마스터하세요

모든 질문, flashcards, 기술 테스트, 코드 리뷰 연습, 면접 시뮬레이터에 접근하세요.

무료로 시작하기