O'Reilly logo

Instant Mockito by Marcin Grzejszczak

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Quick start – creating your first unit test with Mockito

A unit test is a piece of code that verifies whether your smallest testable part of your application does what it is supposed to do. There are plenty of benefits of unit tests, such as early tracing of errors, stress free code refactoring, and living code documentation. In the following example we will not focus on the advantages of unit tests themselves, but on how easily one can create test doubles by using Mockito.

In this quick start guide, let us assume that we already have a simple application (that's why we will not do Test Driven Development) for ordering meals that we would like to unit test.

Step 1 – picking a class that you want to unit test

We would like to unit test a class that ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required