Skip to content

Latest commit

Β 

History

History
62 lines (53 loc) Β· 1.83 KB

File metadata and controls

62 lines (53 loc) Β· 1.83 KB

Spring Testcontainers(SpringBoot 3.1+)

This is an example of configuring a MySQL integration test based on Testcontainers utilizing @ServiceConnection in Spring Boot 3.1+

πŸ“¦ Project Spec Summary

βœ… Language & Platform

  • Language: Kotlin 1.9.25
  • JVM Target: Java 21 (Toolchain)
  • Build Tool: Gradle (Kotlin DSL)
  • Spring Boot: 3.5.4

βœ… Plugins

  • kotlin("jvm"): 1.9.25 - Kotlin β†’ JVM compile
  • kotlin("plugin.spring"): 1.9.25 - Kotlin + Spring plugin
  • kotlin("plugin.jpa"): 1.9.25 - JPA entity no-arg/open plugin
  • org.springframework.boot: 3.5.4 - Spring Boot plugin
  • io.spring.dependency-management: 1.1.7 - dependency BOM and mangement

βœ…Dependencies

▢️ Spring Boot

  • org.springframework.boot:spring-boot-starter
  • org.springframework.boot:spring-boot-starter-data-jpa
  • org.springframework.boot:spring-boot-starter-test
  • org.springframework.boot:spring-boot-testcontainers

▢️ MySQL

  • com.mysql:mysql-connector-j

▢️ Testcontainers

  • org.testcontainers:mysql
  • org.junit.platform:junit-platform-launcher

▢️ Kotlin

  • org.jetbrains.kotlin:kotlin-reflect
  • org.jetbrains.kotlin:kotlin-test-junit5

πŸ“ Project Directory Structure

.
β”œβ”€β”€ main
β”‚    β”œβ”€β”€ kotlin.com.chapakook.lab.springtestcontainers
β”‚    β”‚   β”œβ”€β”€ domain.user
β”‚    β”‚   β”‚    β”œβ”€β”€ User.kt
β”‚    β”‚   β”‚    └── UserRepository.kt
β”‚    β”‚   └── SpringTestcontainersApplication.kt
β”‚    └── resources
β”‚        └── application.yaml
└── com.chapakook.lab.springtestcontainers.domain.user
     β”œβ”€β”€ UserRepositoryTest.kt
     └── UserRepositoryTestWithServiceConnection.kt

βš™οΈ application.yaml

spring:
  application:
    name: service-connection
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true