2013-10-05 57 views
0

我有一個問題,我的道測試:春道測試defaultRollback不工作

@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration(locations={"/cmn-dao-spring.xml"}) 
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true) 
public class ScoreDaoTest extends TestCase { 

@Autowired 
private ScoreDao mScoreDao; 

@Autowired 
private ScoreCreator mScoreCreator; 

@Autowired 
private QuestionCreator mQuestionCreator; 

@Override 
protected void setUp() throws Exception { 
    super.setUp(); 
} 

@Test 
public void testLoadAllScore() throws Exception { 
    List<Score> lAllScore = mScoreDao.loadAllScore(0, 0); 
    Assert.assertTrue(lAllScore.isEmpty()); 
} 

@Test 
public void testSaveScore() throws Exception { 
    Question question = mQuestionCreator.createQuestion(49954854L, new Date(), "Wer bist Du?", "Jörg", "Anja", "Stefan", "Willi", 3, true, false, 1, "DE", "DE_QZ"); 
    Assert.assertNotNull(question); 
    mScoreDao.saveScore(mScoreCreator.createScore(-1L, null, "Stefan", 1033, 27, "Wuhuuuu", question)); 
    List<Score> lAllScore = mScoreDao.loadAllScore(0, 1); 
    Assert.assertFalse(lAllScore.isEmpty()); 
} 

} 

每次我跑我的測試類的數據永久保存。但我不想爲我的測試課程。

我沒有看到問題。

回答

1

您的測試不是事務性的,所以Spring沒有任何回滾事務。

@Transactional添加到測試方法(或測試類,如果您希望其所有測試方法都是事務性的)。

+0

你是對的。與Transactional它的作品。多謝。只是爲了興趣,爲什麼是@TransactionConfiguration? –

+0

要指定Spring如何處理事務性測試事務:要使用哪個TxManager,是否必須回滾或提交。 –