Skip to main content
CF

Learn Java Unit Testing with Junit & Mockito in 30 Steps

4h 44m 35s
English
Paid

Learn how to write clear and solid unit tests with JUnit and Mockito. This page gives you a simple guide to what you will study in the course. You see the key skills you will build and how each step fits into real Java work.

What You Will Learn

You take 12 steps with JUnit and 18 steps with Mockito. Each step shows you a small idea. You use that idea in short and focused tests. By the end, you know how to test code with less setup and fewer mistakes.

Mockito Steps

Start With Mocks

  • Set up a project with JUnit and Mockito. Run your first green test.
  • See why mocks help you test code that calls other classes.
  • Learn what a stub is. Write a test with a stub and see its limits.
  • Write your first mock with Mockito. Mock a simple service.

Stubbing and Verification

  • Stub methods with return values, matchers, and errors.
  • Use simple BDD terms: Given, When, Then. Write tests with BDD style.
  • Check how many times a method runs on a mock.
  • Capture values passed into a mock using an argument captor.

Useful Mockito Tools

  • Use Hamcrest matchers to improve test checks.
  • Use annotations like @Mock, @InjectMocks, and @Captor.
  • Learn how MockitoJUnit.rule() works.
  • Apply Mockito in a small Spring example.

Advanced Mocking

  • Spy on real objects and see when to use a spy.
  • Learn why Mockito does not mock final or private methods.
  • Use PowerMock to mock static methods.
  • Call private methods with PowerMock.
  • Mock a constructor when needed.
  • Review what makes a good unit test.

JUnit Steps

Start With Basics

  • See why unit tests matter in everyday Java work.
  • Set up your first JUnit test.
  • Write a simple assertEquals test.
  • Refactor your first test to make it cleaner.

Core Test Skills

  • Use assertTrue and assertFalse.
  • Run setup and cleanup code with @Before and @After.
  • Run class‑level setup with @BeforeClass and @AfterClass.
  • Compare arrays in a test.

More JUnit Tools

  • Test expected errors.
  • Measure simple performance with JUnit tools.
  • Write parameterized tests.
  • Group tests into suites.

About the Author: Udemy

Udemy thumbnail

Udemy is the largest open marketplace for online courses on the internet. Founded in 2010 by Eren Bali, Oktay Caglar, and Gagan Biyani and headquartered in San Francisco, the company went public on the Nasdaq in 2021 under the ticker UDMY. The platform hosts well over two hundred thousand courses across software development, IT and cloud, data science, design, business, marketing, and creative skills, taught by tens of thousands of independent instructors. Roughly seventy million learners use it worldwide, and the corporate arm — Udemy Business — supplies a curated subset of that catalog to enterprise customers.

Because Udemy is a marketplace rather than a single editorial publisher, the catalog is uneven by design. The strongest material lives in the long-form, project-based courses authored by working engineers — full-stack JavaScript, React, Node.js, Python data science, AWS, Docker and Kubernetes, mobile development with Flutter and React Native, and cloud certification preparation. The CourseFlix listing under this source is the slice of that catalog that has been mirrored here for offline-friendly viewing, organized by topic and updated as new releases land. Pricing on Udemy itself swings dramatically with the site's near-permanent sales, which is why the platform is best treated as a deep reference catalog: pick instructors with strong reviews and a track record of updating their material rather than buying on the headline price alone.

Watch Online 36 lessons

This is a demo lesson (10:00 remaining)

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

View Pricing
0:00
/
#1: Introduction
All Course Lessons (36)
#Lesson TitleDurationAccess
1
Introduction Demo
02:19
2
Three thing you need to know
01:46
3
JUnit Step 1 : Why is Unit Testing Important?
03:42
4
JUnit Step 2 : Setting up your first JUnit
08:06
5
Step 03 : First Successful JUnit. Green Bar and assertEquals
09:40
6
Step 04 : Refactoring Your First JUnit Test
07:45
7
Step 05 : Second JUnit Example assertTrue and assertFalse
14:46
8
Step 06 : @Before @After
07:03
9
Step 07 : @BeforeClass @AfterClass
03:31
10
Step 08 : Comparing Arrays in JUnit Tests
05:20
11
Step 09 : Testing Exceptions in JUnit Tests
03:34
12
Step 10 : Testing Performance in JUnit Tests
04:04
13
Step 11 : Parameterized Tests
11:12
14
Step 12 : Organize JUnits into Suites
03:25
15
An Overview
01:54
16
Mockito Step 01 : Setting up a Maven Project
07:32
17
Overview of this Section
02:11
18
Mockito Step 02 : Setting up SUT (System Under Test)
11:03
19
Step 03 : Stubbing Example - with Disadvantages of Stubbing
11:44
20
Step 04 : Your first Mockito code! Hurrah!!!
18:55
21
Basics of Mockito - Section Overview
01:06
22
Step 05 : Stubbing variations with Mockito - Argument Matchers & More...
13:05
23
Step 06 : BDD Style - Given When Then
13:29
24
Step 07 : Verify calls on Mocks
08:53
25
Step 08 : Capturing arguments passed to a Mock
08:44
26
Step 09 : Hamcrest Matchers
11:42
27
Step 10 : Mockito Annotations - @Mock, @InjectMocks, @RunWith, @Captor..
10:01
28
Step 11 : Mockito Junit Rule
03:41
29
Step 12 : Real world Mockito Example with Spring
16:09
30
Step 13 : Mockito Spy
10:04
31
Step 14 : Theory : Why does Mockito not allow stubbing final & private methods?
04:26
32
Step 15 : Setting up PowerMock and SystemUnderTest
08:38
33
Step 15 : Continued. Mocking Static Method
12:32
34
Step 16 : Invoking Private Methods
05:44
35
Step 17 : Mocking a Constructor
09:26
36
Step 18 : Writing Good Unit Tests
07:23
Unlock unlimited learning

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

Learn more about subscription

Related courses

Frequently asked questions

What is Learn Java Unit Testing with Junit & Mockito in 30 Steps about?
Learn how to write clear and solid unit tests with JUnit and Mockito. This page gives you a simple guide to what you will study in the course. You see the key skills you will build and how each step fits into real Java work. What You Will…
Who teaches this course?
It is taught by Udemy. You can find more courses by this instructor on the corresponding source page.
How long is the course?
It contains 36 lessons with a total runtime of 4 hours 44 minutes. Every lesson is available to watch online at your own pace.
Is it free to watch?
It is part of CourseFlix's premium catalog. A subscription unlocks the full video player; the course description, table of contents, and preview information are available to everyone.
Where can I watch it online?
The course is available to watch online on CourseFlix at https://courseflix.net/course/learn-java-unit-testing-with-junit-mockito-in-30-steps. The page hosts every lesson with the integrated video player; no download is required.