Tags » Mockito

How to do an unit test using Mockito


What will we do?

Before, we have seen how we could access data from our database using Spring Data, today we are going to see how we can test our classes. 561 more words


Testing a cacheable method with Mockito

The Spring framework provides a simple way to cache the value returned by a method.
Basically, you annotate a method with @Cacheable and next time you call it with the same arguments, you get the cached value avoiding re-executing the method’s code. 1,251 more words


Using ArgumentCaptor class

Suppose we have classes as shown below

class Class1 {
private Class2 class2;

public Class1() {
class2 = new Class2();

public void method1(int val) { 224 more words


Test doubles

  • dummy object
  • test stub
  • test spy
  • mock object

In general, test doubles are used to replace DOCs. Mockito is one of several tools which help us create and use test doubles in our test code. 103 more words


Interactions in Unit Tests

Direct interactions involve the SUT and its client (a test class, in this case). Indirect interactions involve the SUT and DOCs. Another possible classification divides up interactions into inputs and outputs. 67 more words


Test Fixture

The term “test fixture” refers to the notion of a “well known and fixed environment in which tests are run so that results are repeatable”. The steps required to set up such an environment differ, depending on the types of test and tool used, but the basic idea is always the same. 50 more words