Reputation: 402
I had have some difficulties to run my tests in spring boot app that have flyway to manage migrations, all tests up the applications and fail because the flyway try to run migrations.
I have installed H2 and use @DataJpaTest do try fix that, the application start normally but crash because the code that exists on the migration's file. Example:
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TABLE app_user (
id uuid DEFAULT uuid_generate_v4() NOT NULL PRIMARY KEY,
name varchar(200) NOT NULL
);
As you can see all migrations file have postgres syntax, and the properties are hibernate: ddl-auto: validate
So have some way to only in tests create a H2 table from the @Entity without use migrations or all tests run without start spring application? If true can I test repositories without spring application?
Thanks
Upvotes: 1
Views: 1672
Reputation: 120781
I would recommend to disable Flyway and enable Hibernate auto schema creation in the tests.
You can use properties to enable and disable features:
spring.flyway.enabled=false
spring.jpa.hibernate.ddl-auto=create
For example
@SpringBootTest(properties = {
"spring.flyway.enabled=false",
"spring.jpa.hibernate.ddl-auto=create" })
Upvotes: 1