In the previous chapter, we looked at the general principles that guide our testing. Now we’re going to dive deeper into specific approaches to improve our testing for different situations. Whether our goal is cleaner testing of dependencies, better communication in our testing code, or even discovery of edge cases we hadn’t considered, the JVM ecosystem provides many tools to help out, and we will highlight only a few. Let’s start with that ever-present struggle: how to deal with external dependencies effectively when writing integration tests.
As we move up the pyramid from our isolated unit tests, we encounter a variety of obstacles. To integration test against a real database requires that we have a real database available to use! Getting the benefits of that realistic testing implies a huge increase in setup complexity. The statefulness of these external systems also increases the chances of our tests failing, not because of problems with our code but because of unexpected state lingering between tests.