asp.net mvc - How to prevent database effect in C# MVC Unit testing? -
when applying unit testing on insert, update , delete operation. @ time record inserted, updated , deleted in database well.
how possible? can give solution prevent database effect?
thanks,
ideally should using mocking scenarios db interaction there. make sure have separate out db interaction logic , interface driven. can create mock objects, wherein define expectation of db interaction interfaces. example, if example insertsomething() method called, should returned method? , on. sharing links on details unit testing , mocking.
https://msdn.microsoft.com/en-us/library/ff650441.aspx
http://www.developerhandbook.com/unit-testing/writing-unit-tests-with-nunit-and-moq/
testing mvc controller fails null reference exception
as option, can go separate real database testing purpose, if essential execute tests against database. can also, execute sql script @ start , after running test seed , clean data respectively keep database pristine
Comments
Post a Comment