Improve your coding skills from beginner to expert with the largest online Java e-learning platform

Test Driven Development

with JUnit and Mockito
  • This course covers the fundamentals of test driven development... not just the theory, but how to use it in real world project examples. This includes mocking with Mockito.
  • The course is valid for all current Java versions (7 and up) and covers JUnit 4 and JUnit 5.
  • The code files for this course are split into 2 sections. Users of Java versions 9 and above should use the JUnit 5 version of the code. Users of Java 8 and below should use the JUnit 4 version.


This course requires basic Java knowledge only. No prior knowledge of JUnit is needed.

Contents - 4 hours


Having problems? check the errata for this course.


Introducing TDD

3m 6s

What will we test

2m 36s


Introducing our first example project

2m 2s

Using the IntelliJ IDE

8m 10s

Creating a project structure for test cases

5m 0s

JUnit Basics

8m 31s

First tests

Thinking about examples and outcomes

2m 57s

Step 1 - getting to red

6m 8s

Step 2 - getting to green

2m 29s

Why you must always start with a failing test!

4m 39s

Adding more tests

5m 52s

Finally writing some code

7m 39s

Practising the basics

Testing for exceptions - and challenge number 1

9m 41s

Challenge 2 - writing a test

2m 38s

Solution to challenge 2

3m 36s

Getting to more complex requirements and finding hidden bugs

11m 48s

Challenge 3 - Adding further business requirements

11m 33s


Getting started with refactoring - extracting constants

5m 43s

More refactoring - restructuring our code

4m 32s

Best practice

What is a good or bad test?

6m 58s

JUnit Asserts

5m 24s


The challenge of testing code that has dependencies

3m 55s

Creating a test stub using just Java

14m 10s


Why we want to test behaviour as well as logic

5m 58s

Setting up Mockito and creating a mock

8m 44s

Using mocks to test behaviour

9m 22s

Mockito syntax options

2m 36s

Dummies, Fakes and avoiding Tautologies

What are Fakes or Dummies

5m 5s

Practical exercise - using Mockito to create a stub

4m 30s

Refactoring our tests - using setup and teardown

7m 32s

How to avoid tautologies

9m 17s

Putting it into practice & spying - handling legacy code

Loading up the case study

4m 27s

Understanding the challenge part 1

8m 21s

Understanding the challenge part 2

8m 34s

Using a Spy

13m 1s

Practical exercise - finding the fault in the business logic

14m 22s

Let the Course Come to You

About Us Pricing Frequently Asked Questions Contact Privacy T&Cs Affiliates and Resellers
Facebook Twitter YouTube LinkedIn