Programming 101 states:
Don’t copy and paste code. If you find yourself doing something repetitive then do it right so you can reuse the same code. Functions, classes and even separate files all serve this end.
Now that I’m writing tests all the time I often find myself creating Mocks. Mocks are where you tell code to use a pretend version of some functionality instead of the real one. It could be because the real one does something you don’t want in your tests (writes files, reads a database) or it could be that you’ve got some messy legacy code you can’t to pull into your tests (yet). There’s other reasons too but you get the idea.
So if I make a Mock version of a class it makes sense to try and share that with everyone else that might be trying to test with that same class. Or does it?Continue reading “Are mocks/fakes reusuable?”