Unit Test

A test that exercises the smallest unit of publicly exposed code.

“Smallest unit of publicly exposed code” depends on a few factors. For a library, this could be a public method in the library. For a REST API, the unit in question is (or at least should be) a REST call.

Why Not Lower Level Testing?

The reason why testing does not occur below this level (the “unit”), is because of subtle issues that cascade problems later on. When digging deeper into code for testing purposes, it becomes easy to start testing implementation, rather than the feature itself.

When this happens, any subsequent change in implementation will require refactoring unit tests. This is a smell. The most well-written unit tests allow the implementation to change without breaking the test.