Skip to content

Instantly share code, notes, and snippets.

Last active March 6, 2019 12:10
What would you like to do?
@ContextConfiguration(classes = {DbConfig.class})
@Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:dao/TestData.sql")
public class PostgresEmbeddedDaoTestingApplicationTests {
/* Here we have a static postgreSQL test container Class rule to make the instance used
for all test methods in the same test class , and we use @Transactional to avoid any dirty data changes between
different test methods , where we pass our test database configuration ,
ideally that should be loaded from external config file */
public static PostgreSQLContainer postgreSQLContainer = (PostgreSQLContainer) new PostgreSQLContainer(
private CustomerRepository customerRepository;
public void contextLoads() {
.id(new Random().nextInt())
Assert.assertTrue(customerRepository.findCustomerByName("TestName") != null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment