Testing Against Real External Dependencies

Get familiar with integration tests that deal with system interfaces with external components by using the real dependency.

Many applications interact with databases, other services, or third-party APIs. This makes integration testing harder since we have to deal with other running systems to design and run our integration test suite.

There are two main approaches to dealing with an external dependency in tests:

  • Use the real dependency
  • Replace the real dependency with something that doubles as the dependency

Testing using the real dependency

Say a database backs up our application. The database is a dependency that’s external to the application since it’s not running inside it. For our purposes, we can see it as a black box that we can assume works correctly if used correctly. Let’s imagine that our application uses this database to store blog articles and that it provides an HTTP API as the interface for creating articles. We have an Article struct that represents an article:

Get hands-on with 1200+ tech skills courses.