Testcontainers
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
start a real PostgreSQL for tests from code.
الموضوعات المخطط لها
- Testcontainers starts Docker containers from JUnit tests and removes them afterwards.
@Testcontainerswith@Containermanages the lifecycle.- Spring Boot's
@ServiceConnection(Boot 3.1 or later; verify version before recording) configures the datasource from the container, with no URL copying. - Older style:
@DynamicPropertySourcesets properties from the container. - Make the container
staticso one container serves all tests in the class. - Share one container across classes (singleton or reuse) to save startup time.
تفاصيل المخطط المبدئي
عرض عملي
@Testcontainers
@SpringBootTest
class OrderIT {
@Container @ServiceConnection
static PostgreSQLContainer<?> db = new PostgreSQLContainer<>("postgres:16");
}اختبر فهمك
What does @ServiceConnection replace?
أظهر الإجابة
Manually copying the container URL and credentials into properties.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.