Welcome to the world of Testcontainers for Database Testing & Message Brokers with Python!
This guide is a dedicated resource to help developers understand and utilize Testcontainers for database testing and message-driven applications in various environments.
It covers setup, core concepts, database testing, message brokers, and best practices.
This guide covers everything you need to know about database testing and message brokers with Testcontainers:
- Setup: Instructions for setting up your environment and troubleshooting common issues.
- Core Concepts: Fundamental concepts essential for understanding Testcontainers.
- Database Testing Examples: Hands-on implementations for various databases.
- Message Brokers: How to test RabbitMQ, Kafka, and Redis.
- Best Practices: Writing clean, efficient, and reliable tests.
testcontainers-python-guide/
βββ README.md
βββ setup/
β βββ environment_setup.md
β βββ troubleshooting.md
βββ core_concepts/
β βββ core_concepts.md
β βββ accessing_logs.md
β βββ health_checks.md
βββ database_testing/
β βββ postgres_example/
β βββ mysql_example/
β βββ mongodb_example/
βββ message_brokers/
β βββ rabbitmq_example/
β βββ kafka_example/
β βββ redis_example/
βββ best_practices/
β βββ clean_tests.md
β βββ optimizing_startup.md
β βββ resource_management.md
-
Clone this repository:
git clone https://github.com/vellankikoti/testcontainers-db-message-brokers.git cd testcontainers-db-message-brokers
-
Install the prerequisites:
- Python 3.7+
- Docker
- Docker Compose (optional, for multi-container examples)
-
Navigate to any example directory and follow the README instructions.
- Testing database connections and queries using Testcontainers for PostgreSQL.
- Includes sample queries, transactions, and rollback tests.
- Testing schema migrations and data integrity using Testcontainers for MySQL.
- Sample test cases for CRUD operations.
- Testing NoSQL queries and indexing using Testcontainers for MongoDB.
- Example scenarios for schema-less validation.
- Testing message queueing, pub/sub models, and event-driven architectures with Testcontainers for RabbitMQ.
- Simulating producer-consumer workflows.
- Testing distributed event streaming with Kafka.
- Example scenarios for producing and consuming messages in a microservices architecture.
- Using Testcontainers for Redis caching and pub/sub testing.
- Ensuring cache consistency and expiry testing.
- Write isolated tests to avoid interdependencies.
- Use test fixtures to manage database states.
- Leverage database snapshots to speed up tests.
- Optimize container startup times for CI/CD efficiency.
- Use parallelized testing to speed up execution.
We welcome contributions! Here's how you can help:
-
Choose the appropriate section for your example:
- Database Testing β
database_testing/
- Message Brokers β
message_brokers/
- Database Testing β
-
Create a new directory following the naming convention:
section_name/your_example_name/
-
Include these files in your example directory:
README.md
(explaining the example)requirements.txt
(Python dependencies)- Source code files
- Test files
- Docker configurations (if needed)
- Fork the repository.
- Create a feature branch:
git checkout -b feature/NewExample
- Commit your changes:
git commit -m 'Add new example'
- Push to your branch:
git push origin feature/NewExample
- Open a Pull Request.
- Official Testcontainers Documentation
- Python Testcontainers Documentation
- Docker Documentation
- Kubernetes Documentation
If you find this guide helpful, please give it a star! β It helps others discover this resource.
Made with β€οΈ by the Community