code as you write it. While this is software testing, it’s not
structured and often is not repeatable. Did you test all
options? Did you validate your expectations? What
happens if you send unexpected input to a function?
These are some of the reasons using a structured and
automated testing methodology is crucial to creating
resilient software.
A unit test is a type of test that is conducted on small,
functional aspects of code. It’s the lowest level of
software testing and is interested in the logic and
operation of only a single function in your code. That’s
not to say that you can’t perform multiple tests at the
same time. Computers are great at performing repetitive
tasks, but the goal is for each test to be on one function at
a time so that the testing is specific and consistent.
Remember that a unit is the smallest testable part of
your software.
There are other types of testing that you may hear about,
such as integration testing and functional testing. The
differences between these types of testing and unit
testing come down to the scope of the test. As
mentioned, a unit test is testing a small piece of code,
such as a method or function. An integration test, on the
other hand, tests how one software component works
with the rest of the application. It is often used when
modules of an application are developed by separate
teams or when a distributed application has multiple
components working together. A functional test (also
called an end-to-end test) is the broadest in scope from a
testing perspective. This is where the entire system is
tested against the functional specifications and
requirements of the software application. Figure 5-2
shows a testing pyramid to put it in perspective.