c# - How to convert integration tests to unit tests -
this question has answer here:
- how unit test object database queries 13 answers
i've been tasked changing else's integration tests unit tests. have business objects talk database. , our tests reflect that. problem have code calls db directly within method - , want hit mock data instead of db. how do that?
list<listofstuff> listing = getdatafromdb(dbstuff); //this want //not happen in test. i can't change method, , read wrapping method in interface, i'm unsure of how that...
you can use ms fakes
fakes let change
getdatafromdb(dbstuff); does, better write code uses dependency injection , getdatafromdb accessed via interface.
this simple fake example.
shimdatetime.nowget = () => new datetime(2012, 12, 21); we making datetime.now return 21/12/2012 :) can same getdatafromdb call.
steve
Comments
Post a Comment