vendredi 11 septembre 2020

Spring boot - Test classes not letting go of database connections after finishing

I have a Spring Boot application where I need to test everything. I have run into this problem.

When I launch my tests (for example from Gitlab pipeline), tests are running fast from the beginning. But the more tests are done, the slower it gets. Loading Spring application context for another test class gets slower and slower. I have also found out, that during the tests, database connections stays active and application lets go of them after all of the tests are finished, even though most of the classes have already finished a long time ago. Have anyone run into this problem before and found solution for it please?

My annotations used in tests:

// Service test class example
@ExtendWith(SpringExtension.class)
@DataJpaTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@Import({SomeService.class})
@Sql("classpath:testdata/some_test_data.sql")
public class SomeServiceTest {
// Controller test class example
@ComponentScan(basePackages = {"some.package.with.tests"})
@ExtendWith(SpringExtension.class)
@AutoConfigureMockMvc
@SpringBootTest
@Transactional
@Sql("classpath:testdata/some_test_data.sql")
public class SomeControllerTest {

Aucun commentaire:

Enregistrer un commentaire