Search code examples
unit-testingjpaspring-roo

How do I create a test in Spring Roo to populate a database with test data?


I tried modifying test cases that were generated for my entities, but when I run the tests, it doesn't leave the data in the tables. I tried modifying the persistence.xml (changing the persistence from none to create-tables) but when I run the tests, it throws exceptions because it's trying to update/delete stuff that has foreign key dependencies.

Am I using the wrong tool for this? I was hoping I'd be able to run my tests and be left with a database in a known state. Am I using the tool wrong?


Solution

  • Its probably something to do with the fact that unit test transactions are rolled back after the unit test is done. Maybe having something to do with @TransactionConfiguration(defaultRollback=true)

    I found this other post that might shed some light

    How to rollback a database transaction when testing services with Spring in JUnit?