I want to do these in my vs2005 test class:
My question is how to code in MyTestInitialize() and MyTestCleanup() for begin and rollback the transaction.Code:[TestInitialize()] public void MyTestInitialize() { //begin a transaction //..... } [TestCleanup()] public void MyTestCleanup() { //rollback... //because I don't want the test data update into database. } [TestMethod()] public void DAOTestMethod() { //Use dao to do some database operations. //In dao, I User HibernateTemplate to access database. }
I try these:
but is doesn't work.Code:HibernateTemplate ht = null; public void DAOTestMethod() { this.ht.Execute<SnapShot>(new HibernateDelegate<SnapShot>( delegate(ISession session) { this.DAOTestMethodTaget(); session.Transaction.Rollback();//the transaction is commited. so this code would throw an exception. return null; } ) ); } public void DAOTestMethodTaget() { //.... TestDAO.Save(myTestObj); //.... }
BTW: Any better suggestions for Create Test Case? I just want to test the dao without updating data into database.


Reply With Quote