I did it AGAIN!


I had my mocks set up to expect calls and return things, but the class under test wasn’t getting as far as it should have been, given those inputs.

I began to suspect many things, both plausible and im-:

  • “Maybe JUnit’s gone haywire!”
  • “The coverage tool must be malfunctioning.”
  • “Maybe Eclipse has gotten fouled up building my project due to that unimplemented method I’m calling far away in a different as-yet-unused part of the project”
  • Maybe a system property or environment variable is floating around, somehow interfering (though that shouldn’t matter since I’m mocking the reading of those…)
  • Maybe the mock framework isn’t working (though it seems to be doing fine for all the other test methods…)

Finally, after over an hour had passed, I noticed that in my test I was INSTANTIATING A NEW INSTANCE of my class under test… which of course then wasn’t being injected with my mocks.

I’ve written about this at least twice before…but apparently I haven’t learned my lesson yet!

Note to self: Remember not to instantiate these things manually.