When I use org.junit.rules.Timeout of JUnit with AbstractTransactionalJUnit4SpringContextTests base class of spring, I get this exception :
org.springframework.dao.InvalidDataAccessApiUsageException: no transaction is in progress; Nested exception javax.preistence.TransactionRequiredException: no transactions on the transaction in progress Displays log output:
2010-07-20 09:20: 16 information [Transactional Test ExecutionList. Start New Transaction] Transactions (1): Transaction Manager [org.springframework.orm.jpa.JpaTransactionManager@6a1fbe]; Rollback [true] 2010-07-20 09:20:16 information [TransactionalTestExecutionListenerkendTransaction] after test execution to test reference transactions rolled back [[TestContext @ 17b60b6 testClass = MyIntegrationTest, places = array & lt; String & gt; [ 'Classpath: / reference .xml', 'classpath: /junit-context.xml'], testInstance = MyIntegrationTest @ 10a4d7c, testMethod = myTest @ MyIntegrationTest, testException = org.springframework.dao.InvalidDataAccessApiUsageException: undertake a transaction progress, nested exception javax.persistence.TransactionRequiredException: a transaction is in progress]] here's my test:
@RunWith ( SpringJUnit4ClassRunner.class) @ ContextConfiguration (locations = { "classpath: /context.xml", "classpath: /junit-context.xml"}) @ Tronnsakshn configuration (transaction = Manager = "transaction Manager", Difoltrilbak = true) @transake Chanel Public Class MyEctactTest Abstracts TransactionalGuinet 4 Spying Contextsthess {@Royal Public Timeout GlobalTimeout = New Timeout (30000); @ Test public void myTest () {// Saving Transactional Code to Database ...}} However whenever I decrease the rule, it all works well .
How can I get these two to work properly?
Ah, I did it the way I solved it, that transaction is programmatically Was done to setup.
@Atovair Transaction Manager transaction management; @Test Public Zero Test () {TransactionTemplate transactionTemplate = New TransactionTemplate (transactionManager); TransactionTemplate.execute (New TransactionCallbackWithoutResult () {@Override Zero DoInTransactionWithoutResult Protected (TransactionStatus Status) {status.setRollbackOnly (); // Here is your Test Logic DO}}); } Hope it helps.