Skip to content

@Sql annotation on tests makes schema.sql executed twice #7416

Closed
@savinov

Description

@savinov

Sample to reproduce: https://github.com/savinov/spring-boot-schema-twice

spring-boot 1.4.1, spring-data-jpa, hsqldb (for tests). There is schema.sql and data.sql in the test resources folder. Four test classese are annotated with @RunWith(SpringRunner.class), @DataJpaTest and @Sql. One test class (SchemaTwice3Test) is annotated only with @RunWith(SpringRunner.class) and @DataJpaTest.

Run tests: mvn test

The problem is: schema.sql is executed twice somewhere between SchemaTwice3Test run and other tests run. If add (uncomment) @Sql annotation to the SchemaTwice3Test then there is no problems. If remove (comment) @Sql annotation from all the test-classes then there is no problems too.

Workarond with spring.datasource.continueOnError=true makes all the tests pass, but it's not a solution.

It seems that there is some initialization incompartability between @Sql annotation and org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions