I have integration tests that are executed on top on inmemory database. The signature of each test looks more or less like this:
@RunWith(SpringRunner.class)
@SpringBootTest
@Sql("/clean-data-in-all-tables.sql")
public class SomeTest {
@Test
public void shouldDoSomehting() {}
}
During test-context initialization the DB schema is recreated by Hibernate:
spring:
jpa:
hibernate:
ddl-auto: create-drop
I expect sql script to be executed after initialization of context and after db schema generation. However in some cases clean-data-in-all-tables.sql
is executed before schema generation and it fails because it expects tables which were not yet created.
I have more than 500 tests written in the way I explained and they all were working well until I added few more similar tests.
Tests fail when I execute them together via Gradle or IntelliJ. Note the failed tests are not the tests which were recently added. This are the old tests totally unrelated to the ones I added. What is also strange is that the failed tests work well if I run them one by one through IntelliJ.
It looks like a bug of spring-boot however I still try to find a way to workaround it. At the same time I tried numerous of things to solve the issue however none of them was helpfull.
Please share your ideas on what could help and what could be wrong with my code.
UPDATE:
Found the workaround: changing the spring.jpa.hibernate.ddl-auto
from create-drop
to create
solves the problem.
But the question is still open what is the reason of such strange behaviour?