Hacker News new | ask | show | jobs
by JoeNr76 2098 days ago
"The smallest amount of testable code. Often a single method/function,"

I hate (HAAAAATE) that definition of unit test. That's how some IDEs implemented unit tests, but it's not what was originally meant with the term 'unit'

The unit tests the author means has no value outside testing while you are programming the code. For real value, unit tests shouldn't be bound to the implementation of your code.

Unit tests should test a "unit of functionality", not a technical part of the code.

2 comments

actually the origin of the term unit test means a test can be executed as a unit, it does not has dependencies to other tests. It had nothing to do with testing code in isolation.
That's why they said "often".

A better definition might be "the smallest amount of testable functionality".

Which is a function.
It might start out as a function, then become a factory, then an object and if you bind your test to the implementation details of this code, you will have to rewrite your test every time you refactor your code. Not ideal.