Hands On Workshop: The Art of Unit Testing & TDD in Java & JUnit 5
with Roy Osherove
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.
Learn how to write readable, maintainable, trustworthy unit tests using Java, JUnit 5 and other unit testing tools and frameworks.
Learn how to refactor and test legacy code, and what to do when we cannot change existing code.
Learn the principles of Test Driven Development, and develop new features using TDD.
Learn how to Pair Program, and experience it throughout the course
Learn about mocks, stubs fakes, and the difference between them
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)
What is the “unit” in “unit testing”? A discussion about unit of work.
The first unit test
Basic JUnit 5 APIs, test runners, tips and tricks
Writing readable tests
Test Driven Development Introduction
String Calculator Kata Exercises
Value base, State Based and Interaction Based Tests
Day 2: Mocks & Stubs (09:00-16:00)
Understanding Fakes, Mocks and Stubs
Hand Written Fakes, Stubs and Mocks
Isolation Frameworks: Constrained and Unconstrained
Isolation Framework Comparisons
Exercises
Unit Testing Best Practices
Code Review Exercises
Day 3: Diving Deeper (09:00-16:00)
Legacy Code
Refactoring Exercises:
Faking Time
Extract And Override
Introduce Instance Delegator
Using PowerMock and JMockit to Fake the un-fake-able
Exercises