DEV Community

Discussion on: What exactly is a "unit" in unit testing?

Collapse
 
taimila profile image
Lauri Taimila

My personal experience is that this kind of tests become more of a burden than benefit in a long run. I should know, I've written thousands of tests like in this post. The number one reason why I want tests is safety when refactoring the solution. However, tests with too small unit don't support this. It' rare that refactoring happens in such a limited scope and therefore tests need to be modified simultaniously with production code, which scares me.

Nowadays I write unit tests with larger scope and I recommend giving it a try!

For further reading: taimila.com/blog/unit-of-unit-test...

Collapse
 
aghost7 profile image
Jonathan Boudreau

I think unit tests are not always appropriate. If you're trying to test code which is largely business logic I'd go with unit testing, for example. If you're trying to test code which is very network intensive I would do integration testing or something along those lines instead. You end up doing so much mocking in those situations that it becomes apparent that you're making a lot of assumptions (i.e., the benefit is negligible).

Pick the right tool for the job I suppose.