Why Unit Testing
Unit testing is when you (a programmer) write test code to verify units of code. The size of a unit isn’t precisely defined, so we’ll view a unit as a small bit of code that exhibits some useful behavior in your system. A unit on its own usually doesn’t represent complete end-to-end behavior. It instead represents some small subset of that end-to-end-behavior.
We’re coding in Java, so we write our unit tests in Java, too. We run these unit tests through JUnit, a tool that marks our tests as passing or failing.
Here are a few whens and whys for writing unit tests:
-
You just finished coding a feature and want to ensure that it works as you expect.
-
You want to document a change so that you and others later understand the choices ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access