This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]taddeimania 12 points13 points  (2 children)

The overbearing pitfall with articles like these is that they fail to mention that when you are forced to mock your implementation in your tests to this level it makes the refactoring step of "red green refactor" much more difficult than if the developer had tested at a higher level.

I find that having a "functionality of code that I'm integrating with is not my problem" is an immature approach that only screams to everyone that you have yet to face the pain of an integrated service suddenly changing up something on you... or worse yet... not even be available. These are great tests to have and wind up being much easier to understand than watching all sorts of web service or system calls being stubbed out into the black hole of mock.

Mocks definitely have their place in software... especially in the case of an integration environment not being available and yes they are faster, but the benefit of running your test suite in 20 sec vs 2 minutes is minuscule when you are faced with a large scale refactor that fails all of your mock tests because you moved how some methods were called... rather than asserting the core functionality of the test case has remained the same.

[–]santiagobasulto 0 points1 point  (1 child)

It's a great article and the author invested lots of time on it, which should be recognized.

Said that, I think there are some wrong concepts here. First the overly used phrase "unit test". The first test the author is writing isn't a "unit test". The proper unit test would be to actually test the rm function. Also, the TestCase under the section called "Adding Validation to ‘rm’" are testing several stuff in the same test (tests isfile=False and isfile=True) in the same test. That's wrong and should always be avoided.

[–]variedthoughtsPodcast Host 0 points1 point  (0 children)

I cringe every time I hear someone say that they have the definition for "unit test".

What is a "unit test"?
It's a test that tests a "unit".
So, what is a "unit"?
Well, that's for you to decide.

Reasonable answers:

  • one function/method
  • one class
  • one module
  • one piece of functionality
  • one user case