Когда я использую org.junit.rules.Timeout от Junit с базовым классом Spring AbstractTransactionalJUnit4SpringContextTests, я получаю это исключение:
org.springframework.dao.InvalidDataAccessApiUsageException: no transaction is in progress; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress
Вывод журнала показывает:
2010-07-20 09:20:16 INFO [TransactionalTestExecutionListener.startNewTransaction] Began transaction (1): transaction manager [org.springframework.orm.jpa.JpaTransactionManager@6a1fbe]; rollback [true]
2010-07-20 09:20:16 INFO [TransactionalTestExecutionListener.endTransaction] Rolled back transaction after test execution for test context [[TestContext@17b60b6 testClass = MyIntegrationTest, locations = array<String>['classpath:/context.xml', 'classpath:/junit-context.xml'], testInstance = MyIntegrationTest@10a4d7c, testMethod = myTest@MyIntegrationTest, testException = org.springframework.dao.InvalidDataAccessApiUsageException: no transaction is in progress; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress]]
Вот мой тест:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:/context.xml", "classpath:/junit-context.xml"})
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
@Transactional
public class MyIntegrationTest extends AbstractTransactionalJUnit4SpringContextTests{
@Rule public Timeout globalTimeout = new Timeout(30000);
@Test
public void myTest() {
// transactional code here saving to the database...
}
}
Однако всякий раз, когда я комментирую правило, все работает нормально.
Как я могу жениться на этих двух вместе, чтобы работать правильно?