Deciding When Not to Use Mockito

You likely now have a good grasp of cases for which Mockito is useful. But when is it not the best idea to use Mockito? Let’s explore that question.

If you look in the book’s GitHub repository, you’ll find a test for the getAstroResponse method in the AstroGateway:

 @Test
 void​ ​testDeserializeToRecords​() {
  AstroResponse result = gateway.getResponse();
  result.getPeople().forEach(System.out::println);
  assertAll(
  () -> assertTrue(result.getNumber() >= 0),
  () -> assertEquals(result.getPeople().size(), result.getNumber())
  );
 }

The test instantiates the class and invokes its getResponse method. Then the data is checked to confirm that the number property of the AstroResponse record ...

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.