There is a situation that I want to use a database image to integration test my service layer. Here is the code I developed to setup my Postgres container image:
@SpringBootTest(classes = EventhandlerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
public abstract class BaseIT {
public static final PostgreSQLContainer<?> postgresDB = new PostgreSQLContainer<>
("postgres:12-alpine")
.withDatabaseName("test-db")
.withUsername("postgres")
.withPassword("password");
static {
postgresDB.start();
}
@DynamicPropertySource
public static void properties(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", postgresDB::getJdbcUrl);
registry.add("spring.datasource.username", postgresDB::getUsername);
registry.add("spring.datasource.password", postgresDB::getPassword);
}
}
Now I want to use the test database to call my service layer methods and inspect the results, here is my integration test example:
public class SampleServiceTesting extends BaseIT {
@Autowired
private SampleService sampleService;
@Test
@Transactional
void testIntegrationFlow() {
SampleService.exampleMethod();
}
}
But when I run the test, it returns the following error:
org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
How I can fix this issue on runing my test please?