While attempting to standardize the testing of a code base, I’ve been trying to enable Spring’s test-level transaction management. In a nutshell, if you run a properly configured test within Spring’s test transaction framework then then the test does not actually commit anything to a database.
It should be as easy as annotating your test class like this:
@ContextConfiguration(locations="application-context.xml") @TestExecutionListeners({TransactionalTestExecutionListener.class}) @TransactionConfiguration(transactionManager="myTxManager") @Transactional
This loads the application context from the classpath and then manipulates the transaction manager named myTxManager to roll back the database transaction when the test is complete. The problem I have is that the application context file isn’t on the classpath. To make it even more interesting, it’s stored on a different place on each developer workstation. There’s already a utility to discover the file, I just need to hook it into the context loader.






