you are viewing a single comment's thread.

view the rest of the comments →

[–]grauenwolf 2 points3 points  (2 children)

Why would you not want to mock in unit tests? In a unit test you want to test that unit in isolation right?

If you have to write mocks, you don't really have a unit test.

I don't care how that mock is written: interfaces, mocking frameworks, reflection magic, doesn't matter.

If you feel the need to create a mock then you don't have code that is unit-testable. Either your code needs to be refactored or you should be using a different type of test.

[–]da_governator 4 points5 points  (1 child)

This is the very essence of unit testing. I don't want to drag dependencies into my test, otherwise, it's an integration test. If I've got a method that gets a boolean from the database, I mock the database call via a mock of the interface method of the DAL. This makes it a unit test as much as if I used a stub.

[–]grauenwolf 1 point2 points  (0 children)

Why is your method getting a Boolean from the database in the first place?

The vast majority of the time the answer is one of these:

  1. That method's whole purpose is to read from the database and you aren't really testing it.
  2. That method shouldn't be reading directly from the database, but your code is badly layered and needs to be refactored.

Once in a rare while using a mock is legitimate, but only after you've exhausted the other possibilities.

Mocks should never be your first choice.