Reputation: 20549
Is a unit a class or a component(more than one class)?
What should be a unit test? How granular should be a unit?
Upvotes: 3
Views: 472
Reputation: 136613
The term (similar to many other things associated with Agile) is overloaded (means different things to different people). It has undergone a lot of flux and is now subjective. Some have come up with a new term microtests to prevent confusion.
Earlier it was meant to mean function-level white-box testing. As a rule of thumb, a unit is usually a behavior exposed by a class (usually as a method). Among TDD practitioners, there are two camps
My current understanding is that it's a deliberate choice per unit-test ; one style does not fit all.
Upvotes: 5
Reputation: 37566
A unit is the smallest testable part of the application, usually a function.
Upvotes: 5
Reputation: 5057
I would put it like this: a unit in a unit test is an entity for which a defined output is expected for a known input. The level of granularity however can vary dramatically: from a function to a class to the whole program.
Upvotes: 3
Reputation: 27601
It can be a class. It can be more than one class. It can be the entire system. It's a logical piece that takes input and gives output -- however those are defined for that component.
Upvotes: 2