There is an agnostic way to create a database if you use Spring with Hibernate.
Ensure that the application context is created / destroyed before / after each testing method:
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({"classpath*:application-context-test.xml"}) @TestExecutionListeners({DirtiesContextTestExecutionListener.class, DependencyInjectionTestExecutionListener.class}) @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) public abstract class AbstractTest { }
To instruct Hibernate to automatically create a diagram at startup and abandon the diagram at shutdown:
hibernate.hbm2ddl.auto = create-drop
Now before each test
- the application context is created and the necessary Spring beans (spring) are introduced
- database structures are created (hibernation)
- import.sql is executed if present (sleep mode)
and after each test
- application context is broken (spring)
- The database schema is discarded (sleep mode).
If you use transactions, you can add a TransactionalTestExecutionListener .
tekbe
source share