I have a spring boot project and I am writing tests for it. I am using a h2 database. My ApplicationTests has these annotations:
@RunWith(SpringRunner.class)
@SpringBootTest
@Sql( scripts = { "classpath:db/data.sql" }, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED))
@ActiveProfiles("test")
I know that the data in data.sql is inserted because if I put an incorrect sql statement in it I get an error when starting the tests so data.sql is run on the h2 database. My data.sql looks like this:
INSERT INTO language VALUES (1, 'English');
When my first test starts I count the records in the language table and there are none. Either the data in data.sql is not being commited or somewhere spring is doing a rollback meaning the data is not in the h2 database anymore and not accessible during tests. Does anybody have a clue what's going on?