Home » Core Java » Mockito

Mockito

Mockito Mock Database Connection Example

A unit test should test a class in isolation. Side effects from other classes or the system should be eliminated if possible. Mockito lets you write beautiful tests with a clean & simple API. In this example we will learn how to write a simple test case using Mockito. Tools and technologies used in this example are Java 1.8, Eclipse ...

Read More »

Mockito List Matcher Example

In the Mockito Tutorial for Beginners, we saw a general overview of the use of Mockito framework for Java unit tests. In this example,we will see how are and how to use the Mockito Matchers for List elements. For this example, we will use: Java 1.7.0 Eclipse Mars 2, release 4.5.2. JUnit 4. Mockito 1.10.19. Tip You may skip project ...

Read More »

Mockito Test Case Example

A unit test should test a class in isolation. Side effects from other classes or the system should be eliminated if possible. Mockito lets you write beautiful tests with a clean & simple API. In this example we will learn how to write a simple test case using Mockito. Tools and technologies used in this example are Java 1.8, Eclipse ...

Read More »

Mockito: How to mock a void method call

A unit test should test a class in isolation. Side effects from other classes or the system should be eliminated if possible. Mockito lets you write beautiful tests with a clean & simple API. In this example we will learn how to mock a void method call using Mockito. Tools and technologies used in this example are Java 1.8, Eclipse ...

Read More »

Test-Driven Development With Mockito

In this example we will learn how to do a Test Driven Development (TDD) using Mockito. A unit test should test a class in isolation. Side effects from other classes or the system should be eliminated if possible. Mockito lets you write beautiful tests with a clean & simple API. Tools and technologies used in this example are Java 1.8, ...

Read More »

Writing JUnit Test Cases Using Mockito

In this example we will learn how to write JUnit tests using Mockito. A unit test should test a class in isolation. Side effects from other classes or the system should be eliminated if possible. Mockito lets you write beautiful tests with a clean & simple API. Tools and technologies used in this example are Java 1.8, Eclipse Luna 4.4.2 ...

Read More »

Mockito Maven Dependency Example

A unit test should test a class in isolation. Side effects from other classes or the system should be eliminated if possible. Mockito lets you write beautiful tests with a clean & simple API. In this example we will learn how to define Mockito dependency in maven and how to use it. Tools and technologies used in this example are ...

Read More »

Mockito Initmocks Example

In this example we will learn how to initialize mocks in Mockito. A unit test should test a class in isolation. Side effects from other classes or the system should be eliminated if possible. Mockito lets you write beautiful tests with a clean & simple API. Tools and technologies used in this example are Java 1.8, Eclipse Luna 4.4.2 1. ...

Read More »

Initializing Mockito with InitMocks

In the Mockito Tutorial for Beginners, we saw a general overview of the use of Mockito framework for Java unit tests. In this example, we will see how we can use the InitMocks initialization method, for an easier but expressive way of creating the mocks, specially useful when we have several dependencies to mock. For this tutorial, we will use: ...

Read More »

Mockito Tutorial for Beginners

Mocking is a testing technique widely used not only in Java, but in any other object oriented programming language, that consists in exchanging . There are several mocking testing frameworks for Java, but this tutorial will explain how to use Mockito, probably the most popular for Java language. For this tutorial, we will use: Java 1.7.0 Eclipse Mars 2, release ...

Read More »

Want to take your Java skills to the next level?

Grab our programming books for FREE!

Here are some of the eBooks you will get:

  • Spring Interview QnA
  • Multithreading & Concurrency QnA
  • JPA Minibook
  • JVM Troubleshooting Guide
  • Advanced Java
  • Java Interview QnA
  • Java Design Patterns