Adding Unit and Integration (End-to-End) Tests

For our purposes, an integration test is one that tests a system including components it interacts with (dependencies), whereas a unit test is one that tests a class in isolation with no interactions or dependencies.

Integration tests are often easier to understand because you’re treating the system as it’s used in practice, with no additional information about its implementation. In this case, the system is driven by the getAstroData method on the AstroService, which uses an AstroGateway. Its integration test looks like this:

 @Test
 void​ ​testAstroData_usingRealGateway_withHttpClient​() {
 // Create an instance of AstroService using the real Gateway
  service = ​new​ AstroService(​ ...

Get Mockito Made Clear 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.