Lesson 31Testing Stateful Code
In this lesson, we will look at techniques for unit testing stateful code. We will use many of the same techniques we learned for testing stateless code, but there will be additional work in setting up our tests, and we must be mindful of the order in which we test things.
We will also unit test the service layer for the Class Roster application with a new testing technique called stubbing. We will use stubbed versions of the DAOs in the unit tests for the service layer. This lesson will also explain the motivation and techniques for testing a service layer using stubbed DAOs.
UNIT TESTING STATEFUL CODE
Testing stateful code is a bit more complicated than testing stateless code because, depending on the state of the code, the same set of inputs can produce a different output. For example, say you are testing the account portion of a banking application. Some of the account components include functionality to deposit money, withdraw money, and check the account balance. Now suppose you are testing this component and you want to test the deposit method. You set up your ...
Get Job Ready Java now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.