Skip to content

Instantly share code, notes, and snippets.

@aleixmorgadas
Created December 5, 2023 18:47
Show Gist options
  • Save aleixmorgadas/f1f27d92c93d7fd466279b310908eacf to your computer and use it in GitHub Desktop.
Save aleixmorgadas/f1f27d92c93d7fd466279b310908eacf to your computer and use it in GitHub Desktop.
Signelton Abstract Integration Test to reuse a Testcontainer between test classes
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