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());
}
}
每次我跑我的測試類的數據永久保存。但我不想爲我的測試課程。
我沒有看到問題。
你是對的。與Transactional它的作品。多謝。只是爲了興趣,爲什麼是@TransactionConfiguration? –
要指定Spring如何處理事務性測試事務:要使用哪個TxManager,是否必須回滾或提交。 –