I am using the @DataJpaTest from Spring for my test which will then use H2 as in memory database as described here . I'm also using Flyway for production. However once the test starts FLyway kicks in and reads the SQL file. How can I exclude the FlywayAutoConfiguration and keep the rest as described here in spring documentation in order to let Hibernate create the tables in H2 for me?
@RunWith(SpringRunner.class)
@DataJpaTest
public class MyRepositoryTest {
@Autowired
private TestEntityManager entityManager;
@Autowired
private MyRepository triggerRepository;
}
I resolved the same issue by excluding the autoconfiguration from my application definition, i.e.
Adding the dependency on an in-memory database to my build.gradle
e.g.
testRuntime "com.h2database:h2:1.4.194"
And adding
flyway.enabled=false
to application.properties in src/test/resources worked for me.