This chapter shows how to unit test your APIs before they are integrated with other components. Sometimes, we would have to stub dependencies with some dummy data, and this can be done by mocking the dependencies. We will show you how to do this using a mocking library. We will also show you how to write fixtures to populate test data and then how you can test the behavior of your application by integrating different APIs and testing them together. We will cover the following recipes:

  • Unit testing of an API using JUnit
  • Unit testing by mocking dependencies
  • Using fixtures to populate data for testing
  • Behavioral testing

Get Java 9 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.