3
rutee07
4d

Convoluted mocking hell.

Comments
  • 0
    Have you tried to only mock/stub external dependencies? I don't really see the point in testing test doubles. Doesn't that make refactoring kinda impossible?
  • 1
    Mocking is a fabulous tool that I rarely see used... properly, shall we say. The three camps seem to be:

    - Let's try to get around our awfully designed codebase, that wasn't built with unit tests in mind, by mocking these weird singletons, static classes, etc. in weird ways, such as with static mocking, spying odd parts of a class, etc.
    - I heard mocking is great, but I don't really like to use it, so I mock only the most specific external method calls I have to in order to try to bash the mocks into shape
    - I heard mocking is the BEST THING EVER SO I WILL MOCK ALL THE THINGS AND YOU WILL NOT STOP ME!

    Mocking is a fantastic tool, but IMHO only when it's:
    - Used on a good codebase, with well designed, modular, highly cohesive classes (i.e. classes that only do one thing)
    - Used sparingly, when you actually need to change the *behaviour* of a class for testing, not just its *state*
    - When only the minimum amount necessary on a particular class is mocked.
Add Comment