Skip to content

Instantly share code, notes, and snippets.

@vladdedita
Last active November 21, 2024 23:08
Show Gist options
  • Save vladdedita/ae4cdd3a7c8cf702d6445fcba01524ca to your computer and use it in GitHub Desktop.
Save vladdedita/ae4cdd3a7c8cf702d6445fcba01524ca to your computer and use it in GitHub Desktop.
@ExtendWith(PostgreSQLExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {
// We need to enable lazy initialization to avoid the EntityManager creation during the context loading
"spring.main.lazy-initialization=true"
})
class CleanPostgreSQLTest {
@Autowired
EntityManager entityManager;
@Test
void test() {
// Query data
var result = entityManager.createNativeQuery("SELECT COUNT(*) FROM public.user").getSingleResult();
assertThat(result).isEqualTo(2L);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment