Created
May 17, 2023 14:48
-
-
Save eddumelendez/2a496689f1812490d0b95114d6f6936a to your computer and use it in GitHub Desktop.
This file contains 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
@Testcontainers | |
@JdbcTest | |
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) | |
class PostgresTest { | |
@Container | |
private static final PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:15-alpine"); | |
@DynamicPropertySource | |
static void registerProperties(DynamicPropertyRegistry registry) { | |
registry.add("spring.datasource.url", postgres::getJdbcUrl); | |
registry.add("spring.datasource.username", postgres::getUsername); | |
registry.add("spring.datasource.password", postgres::getPassword); | |
} | |
@Autowired | |
private JdbcTemplate jdbcTemplate; | |
@Test | |
void test() { | |
var records = this.jdbcTemplate.queryForList("select * from profile"); | |
assertThat(records).hasSize(1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment