Reputation: 8477
spring boot web integration test, need load test data first. Now I used below way
@ActiveProfiles("test")
@Sql({"/test-schema.sql","/test-user-data.sql"})
public class FooControllerWebIntegrationTest {...}
it's ok, but I found when execute every test method, it will load test data repeatedly. See below:
2015-12-30 15:58:18.398 INFO 4739 --- [ main] o.s.jdbc.datasource.init.ScriptUtils : Executing SQL script from class path resource [test-schema.sql]
2015-12-30 15:58:18.403 INFO 4739 --- [ main] o.s.jdbc.datasource.init.ScriptUtils : Executed SQL script from class path resource [test-schema.sql] in 5 ms.
2015-12-30 15:58:18.403 INFO 4739 --- [ main] o.s.jdbc.datasource.init.ScriptUtils : Executing SQL script from class path resource [test-user-data.sql]
2015-12-30 15:58:18.412 INFO 4739 --- [ main] o.s.jdbc.datasource.init.ScriptUtils : Executed SQL script from class path resource [test-user-data.sql] in 8 ms.
but I want only load once when test the whole class and even load once when execute mvn package
, how could I do to achieve this purpose?
Upvotes: 1
Views: 2558
Reputation: 3460
What is the problem with loading the schema and data for every test?
If your issue is the schema is recreated for every test, then you can always clean up the schema before the database objects are created.
If your issue is the data created by previous test is not available anymore for the other test, then you have issue with your test because your test should not depends on other tests. Every test should prepare the test data, execute the test and verify the result individually.
Upvotes: 1
Reputation: 24561
This sounds like job for database migration tools like Liquibase or Flyway. Spring Boot has integration for both.
Upvotes: 0
Reputation: 243
If you look at : @Sql annotation documentation
there is a Sql.ExecutionPhase
where you can configure when the sql is executed.
Otherwise you have here the same question answered here:
Upvotes: 0