0

I have a Spring Boot 2.3 reactive application with webflux and r2dbc. Normally it runs on MS Sql database. I want unit tests to run on H2. I got to the point when correct database driver is loaded based on which application.properties file is in use (main or test). But I can't figure out how to run SQL scripts to create schema and load data.

Tried the following without success:

  1. schema-XXX.sql, data-XXX.sql, they work fine with non-reactive JPA.

  2. @Sql annotation referring to the *.sql files in resources directory.

  3. ConnectionFactoryInitializer bean located in the same package as application configuration files, but under the test source tree. @Configuration and @Bean are used properly, but the bean is not instantiated. Maybe this is the problem?

Nothing in the log suggests that there was even a failed attempt to execute *.sql files.

Thank you.

Dmitry
  • 35
  • 1
  • 6
  • there is no such built in out of the box support, you need to run your scripts by your own code – Toerktumlare Jun 09 '20 at 21:24
  • Can you share the annotations you are using on your test class ? It seems the main cause is that your test class is not picking up configuration properly. Just to debug you can use @SpringBootTest, it will load entire server and context but it will make sure all auto configurations get kicked in – Goro Jun 10 '20 at 05:08
  • @Goro I always use `@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)` – Dmitry Jun 10 '20 at 20:54
  • @ThomasAndolf Thank you. – Dmitry Jun 10 '20 at 20:54

0 Answers0