Skip to main content
CF

Hands-On Mocking With Mockito

2h 8m 58s
English
Paid

This course teaches you how to use Mockito in real tests. You learn how to make mock objects, set their behavior, and check how parts of your code talk to each other. The focus is on clear steps and hands-on work.

What You Learn

You work with mocks in small, focused examples. You see how mocks replace real objects during a test. You also learn how mocks help you test hard‑to‑reach code paths.

Create Mocks

You create mock objects with simple code. You use them to test classes that depend on outside systems. This helps you keep tests fast and easy to read.

Control Mock Behavior

You set return values for mock methods. This is called stubbing. You use stubbing to guide the path of your test and cover edge cases.

Check Method Calls

You verify that your code calls the right methods with the right data. You also check how many times a call happens. This gives you clear proof that your code works as planned.

What the Course Does Not Cover

The course does not teach the basics of unit testing in Java. You should know how tests run and how to write simple test cases. The goal here is to help you use the main features of Mockito with confidence.

Additional

https://github.com/rieckpil/hands-on-mocking-with-mockito

About the Author: Philip Riecks

Philip Riecks thumbnail

Filip helps developers release software products more frequently and with greater confidence through practical technical content and applied consulting. He is an indie hacker, often travels around Southeast Asia, plays squash, is learning padel, and enjoys running in nature.

Watch Online 27 lessons

This is a demo lesson (10:00 remaining)

You can watch up to 10 minutes for free. Subscribe to unlock all 27 lessons in this course and access 10,000+ hours of premium content across all courses.

View Pricing
0:00
/
#1: Why Do We Need Mocking
All Course Lessons (27)
#Lesson TitleDurationAccess
1
Why Do We Need Mocking Demo
11:15
2
Important Note About The Terminology
01:20
3
Introduction To The Java Project
02:12
4
The Class Under Test
02:17
5
Understanding How Mockito Creates Mocks
06:59
6
Using @Mock To Create Mocks
04:00
7
Simplify The Setup Using The MockitoExtension
03:27
8
Default Behavior Of Mocks
03:38
9
Stubbing The First Method Call
07:41
10
Exploring ArgumentMatchers
05:09
11
Instructing The Mock To Throw An Exception
03:13
12
Instructing The Mock To Call The Real Method
02:27
13
Using .thenAnswer() Instead of .thenReturn()
06:15
14
Full Mockito Setup For Our Class Under Test
03:19
15
Second Test For Our Class Under Test
02:20
16
How To Stub Void Methods?
05:48
17
Using .doReturn() For Non-Void Methods
02:52
18
Exploring Mockito's BDD Syntax
04:25
19
Introduction To Verifications With Mockito
08:49
20
Verifying in Order
03:02
21
Capturing Method Arguments With ArgumentCaptors
07:30
22
@Mock vs. @Spy
06:17
23
Deep Stubbing
04:27
24
How To Mock Static Methods?
07:51
25
How To Mock Constructors?
03:56
26
@Mock vs. @MockBean
04:40
27
The Four Golden Rules Of Mockito
03:49
Unlock unlimited learning

Get instant access to all 26 lessons in this course, plus thousands of other premium courses. One subscription, unlimited knowledge.

Learn more about subscription

Related courses

Frequently asked questions

What prerequisites are needed before taking this course?
You should already be familiar with the basics of unit testing in Java. This course assumes you know how tests run and how to write simple test cases. It focuses on using Mockito for mocking and does not cover fundamental unit testing concepts.
What types of projects or exercises will I work on in this course?
The course involves working with small, focused examples to practice creating and using mock objects. You will apply these techniques to test classes that depend on external systems, ensuring your tests are both fast and easy to read. These exercises help you understand how mocks replace real objects during tests and how they can be used to reach difficult code paths.
Who is the target audience for this course?
This course is designed for Java developers who have a basic understanding of unit testing and want to learn how to use Mockito effectively. It is particularly useful for those who need to test code that interacts with external systems or has complex dependencies.
How does this course compare in depth to other Mockito courses?
This course focuses on practical, hands-on experience with Mockito's main features. It covers creating mocks, controlling mock behavior through stubbing, and verifying method calls. While it does not cover basic unit testing concepts, it provides detailed guidance on using Mockito for complex testing scenarios, which may offer more practical depth than introductory courses.
Which specific tools and platforms are used in this course?
The course teaches how to use Mockito, a popular framework in Java for creating mock objects in tests. It covers techniques such as using @Mock annotations, the MockitoExtension, ArgumentMatchers, and BDD syntax. The course does not cover other testing frameworks or tools beyond Mockito.
What topics are intentionally not covered in this course?
The course does not cover the basics of unit testing in Java. It assumes you already know how tests run and how to write simple test cases. The focus is on using Mockito to create and control mock objects rather than on foundational testing concepts.
What is the time commitment required for this course?
The course consists of 27 lessons. While the total runtime is not specified, the content is designed to be concise and focused on hands-on practice with Mockito. The time required will depend on your pace of study and prior experience with the material.