6

I just reviewed a pull request with a test case like (pseudo code):

# Test MyService

const mock = createMock(myService.myMethod)
.whenCalledWith("foo")
.returns("bar");
assert(mock.myMethod("foo") === "bar"));

Why though? Why are we testing the mock? What is happening here? This test has no reason of being there instead of a fuzzy feeling that we now have unit test to lure us into a false sense of security.

I asked why we don't do an integration test. Response was: "They are slow."

Well, duh, but at least they would actually test something.

What do you gain by asserting that the mock is working the way you set it up?

Comments
  • 5
    That's why I'm learning to live w/o mockito/powermock/etc. It's always too tempting to write a test that only tests... the mocking framework.
  • 0
    And then they are shocked when prod fails. "But we tested." No, you tested a mock-up, not the app.
  • 1
    The only time you are supposed to mock things during unit tests, are for third part functions which return different outcome depending on when called.

    In practice, I mainly used them for mocking api call responses, which then my function processes it.
Add Comment