---
title: "TDD & Unit Testing in Java workshop"
url: "https://www.artofunittesting.com/tdd-in-java.md"
canonical: "https://www.artofunittesting.com/tdd-in-java"
tags: []
author: "Roy Osherove"
description: "The Art of Unit Testing, 3rd Edition, by Roy Osherove (Manning): readable, maintainable, trustworthy unit tests. Plus hands-on TDD workshops in C#, JavaScript, Java and Kotlin."
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# TDD & Unit Testing in Java workshop

Hands-on workshop · 3 days · with Roy Osherove

# The Art of Unit Testing & TDD in Java & JUnit 5

 ![](https://www.artofunittesting.com/img/c/java.png)

[Book training](https://forms.gle/jQSx5KoXvrVA1JCK7)[Other languages](https://www.artofunittesting.com/languages)

## The Problem

Unit testing, done badly, can hurt your project more than it helps. In some cases, it may lead to project schedule delays, and unhappy developers due to huge maintenance problems. But when unit testing is done right, it can help the project and developers’ confidence immensely. The challenge is - how do you do it in a way that is helping, rather than hurting your project?

## Objective

In this workshop we will learn essential test driven skills and techniques for writing unit tests in a readable, maintainable and trustworthy fashion, so that we can feel more confident in our code, make it simpler, and save ourselves time in debugging and maintaining our code base. we will also look at some code design issues that hurt testability.

1. Learn how to write readable, maintainable, trustworthy unit tests using Java, **JUnit 5** and other unit testing tools and frameworks.
2. Learn how to **refactor** and test **legacy code**, and what to do when we cannot change existing code.
3. Learn the principles of **Test Driven Development**, and develop new features using TDD.
4. Learn how to **Pair Program**, and experience it throughout the course
5. Learn about **mocks, stubs fakes**, and the difference between them
6. Learn about **Isolation(mocking) frameworks**, how they work, and why some frameworks are more capable than others

## Pre-Requisites

- The course will benefit any developer with 1 year’s experience working with Java.
- No unit testing experience required.
- The course will mainly target **.NET Core/.NET 4.X compatible C# frameworks.**
- **Visual Studio Community Edition or higher**, or JetBrains **Rider** required.

## Agenda

### Day 1: Beginnings (09:00-16:00)

1. What is the “unit” in “unit testing”? A discussion about unit of work.
2. The first unit test
3. Basic **JUnit 5 APIs,** test runners, tips and tricks
4. Writing readable tests
5. Test Driven Development Introduction
6. String Calculator Kata Exercises
7. Value base, State Based and Interaction Based Tests

### Day 2: Mocks & Stubs (09:00-16:00)

1. Understanding Fakes, Mocks and Stubs
2. Hand Written Fakes, Stubs and Mocks
3. Isolation Frameworks: Constrained and Unconstrained
4. Isolation Framework Comparisons
5. Exercises
6. Unit Testing Best Practices
7. Code Review Exercises

### Day 3: Diving Deeper (09:00-16:00)

1. Legacy Code

2. Refactoring Exercises:

    1. Faking Time
    2. Extract And Override
    3. Introduce Instance Delegator
3. Using PowerMock and JMockit to Fake the un-fake-able

4. Exercises

## Bring this workshop to your team

Send Roy a message with your team size, dates and location (or remote).

[Book training](https://forms.gle/jQSx5KoXvrVA1JCK7)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
