Java Reference
In-Depth Information
Table 4.3
Three flavors of unit tests: logic, integration, and functional
Test type
Description
Logic unit test
A test that exercises code by focusing on a single method. You can con-
trol the boundaries of a given test method using mock objects or stubs
(see part 2 of the topic).
Integration unit test
A test that focuses on the interaction between components in their
real environment (or part of the real environment). For example, code
that accesses a database has tests that effectively call the database
(see chapters 16 and 17).
Functional unit test
A test that extends the boundaries of integration unit testing to confirm
a stimulus response. For example, a web application contains a secure
web page that only authorized clients can access. If the client doesn't log
in, then trying to access the page should result in a redirect to the login
page. A functional unit test can examine this case by sending an HTTP
request to the page to verify that a redirect (HTTP status code 302)
response code comes back.
may be working on a logic unit test, an integration unit test, or a functional unit test.
Table 4.3 summarizes these unit test types.
Figure 4.3 illustrates how these three flavors of unit tests interact.
The sliders define the boundaries between the types of unit tests. You need all
three types of tests to ensure your code works. Using this type of testing will increase
your test code coverage, which will increase your confidence in making changes to the
existing code base while minimizing the risk of introducing regression bugs.
Strictly speaking, functional unit tests aren't pure unit tests, but neither are they
pure functional tests. They're more dependent on an external environment than
pure unit tests are, but they don't test a complete workflow, as expected by pure
Figure 4.3
Interaction among the three
unit test types: functional,
integration, and logic
 
 
 
 
Search WWH ::




Custom Search