0

So, I have adde Flyway to my application to run integration tests with an embedded H2. I have also added a data script to db/migration/afterMigrate.sql. Everything worked fine with Spring Boot autoconfiguration up until the point that I created a second test class with @SpringBootTest. This class fails execution because Flyway tries to execute afterMigrate.sql again. I can't seem to prevent it from running, I have added the flyway-spring-test library to the project and tried using it but with no luck. The thing I find odd is that the db migration isn't executed again for the second class, just the afterMigrate.sql script.

Eduardo Bueno
  • 134
  • 1
  • 12

1 Answers1

0

This was caused by a @SpyBean in the second class - the Spring context of the first one was not being reused. The workaround for this is creating an abstract class that both test classes extend from, and declaring the beans in it. This is expected behaviour from Spring but has been debated whether it should be or not - see more at https://github.com/spring-projects/spring-boot/issues/7174

Eduardo Bueno
  • 134
  • 1
  • 12