@ContextConfiguration(value = "/applicationContext.xml")
public class JPASpringTest extends AbstractJUnit4SpringContextTests {
@PersistenceContext(unitName="jpadenemelocal")
EntityManager entityManager;
@Autowired
protected PlatformTransactionManager transactionManager;
@Test
public void testInsertRolManyToMany() {
TransactionStatus status = transactionManager.getTransaction(null);
// your code
transactionManager.commit(status);
}
}
9 Aralık 2010 Perşembe
How to write spring tests without spring transactional management facility
As you know, Spring 3.0 test framework does not allow transaction demercation . You should use beforeTransaction or afterTransaction method annotations to implement test logic after or before the transaction . But it means that you should write one class for every test method. As a result, the number of your test classes increase dramatically. Well, here is the solution , I have used AbstractJUnit4SpringContextTests instead of AbstractTransactionalJUnit4SpringContextTests.
Kaydol:
Kayıt Yorumları (Atom)
Hiç yorum yok:
Yorum Gönder