I’ve been following Jose’s advice on mocks at http://blog.plataformatec.com.br/2015/10/mocks-and-explicit-contracts/ and been quite happy with the results thus far.
I’ve come to the point where I need to decide whether to mock the connection to my datastore. I’ll be using a traditional relational database in production to persist state changes in my app. There will be points where my app will need to query the data store to retrieve information to act on, and also put results into the data store. Pretty standard stuff.
So, is the data layer worth mocking? I can see arguments on both sides.
I could skip any abstraction except for what database to connect to in prod vs. dev vs testing. That would be simple and workable.
Or I could build a data interface as a behavior, and implement the behavior for both my relational database and a mock data store used for testing. More work, but then I’ve decoupled the database from my test suite, and left open the possibility for any other crazy data store in the future via building another implementation of the data API behavior.
Has anyone else wrestled with a similar question? Curious to know…