Created
December 5, 2023 18:47
-
-
Save aleixmorgadas/f1f27d92c93d7fd466279b310908eacf to your computer and use it in GitHub Desktop.
Signelton Abstract Integration Test to reuse a Testcontainer between test classes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dev.aleixmorgadas; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | |
import org.springframework.boot.test.context.SpringBootTest; | |
import org.springframework.boot.testcontainers.service.connection.ServiceConnection; | |
import org.springframework.test.web.servlet.MockMvc; | |
import org.testcontainers.containers.PostgreSQLContainer; | |
import org.testcontainers.junit.jupiter.Testcontainers; | |
@Testcontainers | |
@SpringBootTest | |
@AutoConfigureMockMvc | |
public abstract class AbstractIntegrationTest { | |
@Autowired | |
protected MockMvc mockMvc; | |
@ServiceConnection | |
static final PostgreSQLContainer<?> postgresContainer = new PostgreSQLContainer<>("postgres:16.0"); | |
static { | |
postgresContainer.start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment