O'Reilly logo

Instant Mock Testing with PowerMock by Deep Shah

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

Verifying method invocation (Simple)

Verification is a process where we assert that a certain method was invoked by the code under test. PowerMock provides various ways in which we can perform the verification of a method call. This recipe will cover the steps required to verify a method invocation in various scenarios.

Getting ready

Let's start by verifying an instance method. The EmployeeService class had a method called saveEmployee; we are going to implement this method and write tests for it. Fire off your favorite IDE and let's begin.

How to do it...

  1. The responsibility of the saveEmployee method is to save the employee's information to the database (DB). Here is how the code looks for this method:
    /** * The method that will save * the employee ...

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