A practical, minimal Django project designed to showcase and demonstrate best practices for testing web applications built with the Django framework. This repository provides a ready-to-run environment with various types of tests configured to help developers understand, implement, and maintain high-quality testing in their own Django projects.
- Comprehensive Test Suite: Examples of Unit Tests (for models, utility functions), Integration Tests (for views, serializers, forms), and Functional Tests (via Django's
TestCaseandTestClient). - Modern Tooling: Pre-configured for use with modern testing libraries like
pytest(or the standard Djangounittestrunner). - Data Generation: Utilization of libraries like
factory-boyfor creating realistic and reusable test data fixtures. - API Testing: Demonstrations of testing API endpoints, including authentication and permission checks (if Django REST Framework is used).
- CI/CD Ready: Configured for easy integration into Continuous Integration/Continuous Deployment pipelines.
| Technology | Purpose |
|---|---|
| Python | The core programming language. |
| Django | The web framework used. |
pytest (Optional) |
A powerful testing framework. |
factory-boy |
Generating model instances and data fixtures. |
Follow these steps to get a local copy of the project up and running.
- Python 3.x
pip(Python package installer)
-
Clone the repository:
git clone [https://github.com/amirbigg/django-testing.git](https://github.com/amirbigg/django-testing.git) cd django-testing -
Create and activate a virtual environment (recommended):
# For Linux/macOS python3 -m venv venv source venv/bin/activate # For Windows python -m venv venv .\venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Run migrations:
python manage.py migrate
-
Run the development server (optional):
python manage.py runserver
You can run the entire test suite using the standard Django test runner or, if configured, pytest.
python manage.py test