# The Art of Unit Testing: full text > The official site of The Art of Unit Testing, 3rd Edition (Manning) by Roy Osherove, with Vladimir Khorikov: readable, maintainable, trustworthy unit tests, plus Roy's TDD and unit testing workshops. 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/. Source: https://www.artofunittesting.com/ . Generated 2026-10-22T23:45:22.355Z. 0 posts, 13 pages. ## 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/ --- title: "The Art of Unit Testing, 3rd Edition | Roy Osherove" url: "https://www.artofunittesting.com/index.md" canonical: "https://www.artofunittesting.com/" 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/" --- # The Art of Unit Testing > The official site of The Art of Unit Testing, 3rd Edition (Manning) by Roy Osherove, with Vladimir Khorikov: readable, maintainable, trustworthy unit tests, plus Roy's TDD and unit testing workshops. HTML: https://www.artofunittesting.com/ · Guide for AI systems: [llms.txt](https://www.artofunittesting.com/llms.txt) · Full text: [llms-full.txt](https://www.artofunittesting.com/llms-full.txt) ## On the home page 00Official Book Site ### The Art of Unit Testing, 3rd Edition with Examples in JavaScript. Roy Osherove · Manning This expanded edition teaches mocks, stubs and dependency injection in functional, modular and object oriented style. [Buy the book (opens in a new tab)](https://go.osherove.com/aout3) [Explore workshops](https://www.artofunittesting.com/languages) Print + ebook from Manning · Buy links go to Manning and include Roy’s affiliate code. [![Cover of The Art of Unit Testing, Third Edition, by Roy Osherove (Manning)](https://www.artofunittesting.com/img/c/cover-400.jpg)](https://go.osherove.com/aout3) 01The book #### The 3rd edition [The Art of Unit Testing, Third Edition (opens in a new tab)](https://go.osherove.com/aout3) updates an international bestseller to reflect modern development tools and practices. You’ll explore test patterns and organization, working with legacy code, and even “untestable” code. The many tool-agnostic examples are presented in JavaScript, and are carefully designed so that they apply to code written in any language. [More about the 3rd edition](https://www.artofunittesting.com/art-of-unit-testing-3rd-edition) 02Workshops #### Choose Your Language Hands-on unit testing and TDD training with Roy, in the language your team writes. - ![](https://www.artofunittesting.com/img/c/csharp.png) 3-day hands-on workshop ### [TDD & Unit Testing in C#](https://www.artofunittesting.com/tdd-in-c) Learn how to write your first test with NUnit or XUnit, learn about mocks, stubs and fakes with isolation frameworks such as FakeItEasy & NSubstitute, and refactor legacy code so you can test it easily. - ![](https://www.artofunittesting.com/img/c/js.png) 3-day hands-on workshop ### [TDD & Unit Testing in Modern JS](https://www.artofunittesting.com/tdd-in-js) Learn to write unit tests for async and observable code, as well as methods of faking functions, modules and other types of dependencies. You’ll explore test patterns and organization, working with legacy code, and even “untestable” code. - ![](https://www.artofunittesting.com/img/c/java.png) 3-day hands-on workshop ### [TDD in Java with JUnit 5](https://www.artofunittesting.com/tdd-in-java) Learn about the practices of TDD, and use JUnit 5 to test-drive new functionality. On the way you’ll learn about readability, maintainability & trustworthy tests. - ![](https://www.artofunittesting.com/img/c/kotlin.png) 3-day hands-on workshop ### [TDD in Kotlin](https://www.artofunittesting.com/tdd-in-kotlin) Start learning the skills of unit testing and TDD in Kotlin with Kotlin-Test, JUnit 5 & mockk. 03Free resources #### Start here - Article ### [Definition of a unit test](https://www.artofunittesting.com/definition-of-a-unit-test) What a “unit of work” is, and the ten properties of a good unit test. - Checklist ### [Test Review Guidelines](https://www.artofunittesting.com/unit-testing-review-guidelines) Review every piece of test code for readability, maintainability and trust. - Videos ### [Pair Programming](https://www.artofunittesting.com/pairing-videos) Eleven videos of Roy and Raymond Lim test-driving a Go game engine. - Kata ### [String Calculator Kata (opens osherove.com in a new tab)](https://osherove.com/tdd-kata-1) The classic TDD kata Roy created, on osherove.com. 04Work with Roy #### Services by Roy Osherove ![Roy Osherove](https://www.artofunittesting.com/img/author/roy-osherove-2026-photo-480.jpg) I’m the [founder of Legato Labs](https://legatohq.com/), author of [The Art of Unit Testing](https://www.artofunittesting.com/) and also created the [String Calculator Kata](https://osherove.com/tdd-kata-1). I consult & train teams on various engineering practices & related topics such as: - [Unit Testing & Test Driven Development](https://www.artofunittesting.com/languages) - Refactoring & Clean Code - Continuous Delivery, pipelines & visibility dashboards - Team Metrics & KPIs such as cycle time, [Mean time to Recovery](https://web.archive.org/web/20181212105306/http://enterprisedevops.org/article/devops-metric-mean-time-to-recovery-mttr-definition-and-reasoning "Archived copy (Wayback Machine)"), Escaped Bugs, Red-To-Green time, Main-Merge-Time and more. - 01[On-Site Training (opens in a new tab)](https://osherove.com/trainingoptions) - 02On-Site Coaching/Consulting/Pairing - 03Remote Test Reviews - 04Public Training [Book a service](https://forms.gle/jQSx5KoXvrVA1JCK7) 05Testimonials #### From workshop attendees > Rarely are subject experts also great teachers, Roy is the whole package. Blake RhodesSoftware Engineer > Very exciting course with precise balance between theory and practice. Roy is an extremely good listener making me not hesitate to get all the answers I need in a very clear way. Even if you have experience with TDD, I highly recommend his TDD Mastery Training. Diego FariaSoftware Engineer > Roy is an excellent speaker with a good pace on his course. I will definitely implement what I learn. Marcio Carneiroreis > Perfect course, liked the content and educational guidance! Recommend it highly! Marco Pasopas > Great course for junior/mid level specialists wanting to start changing their thinking to TDD way of thinking. Aleksandras Gavinciuk 06Contact #### Bring a workshop to your team Training, coaching or remote test reviews: send Roy a message. [Contact Roy](https://forms.gle/jQSx5KoXvrVA1JCK7)[See services](https://www.artofunittesting.com/services-and-pricing) ## Pages - [The Art of Unit Testing, 3rd Edition](https://www.artofunittesting.com/art-of-unit-testing-3rd-edition.md): The Art of Unit Testing, Third Edition, by Roy Osherove (Manning): mocks, stubs and dependency injection in functional, modular and object oriented style, with examples in JavaScript. - [Choose Your Language: TDD workshops](https://www.artofunittesting.com/languages.md): Hands-on unit testing and TDD workshops by Roy Osherove in C#, modern JavaScript, Java (JUnit 5) and Kotlin. - [TDD & Unit Testing in C# workshop](https://www.artofunittesting.com/tdd-in-c.md): 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. - [TDD & Unit Testing in Modern JavaScript workshop](https://www.artofunittesting.com/tdd-in-js.md): 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. - [TDD & Unit Testing in Java workshop](https://www.artofunittesting.com/tdd-in-java.md): 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. - [TDD & Unit Testing in Kotlin workshop](https://www.artofunittesting.com/tdd-in-kotlin.md): 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. - [Definition of a Unit Test](https://www.artofunittesting.com/definition-of-a-unit-test.md): 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. - [Test Review Guidelines](https://www.artofunittesting.com/unit-testing-review-guidelines.md): 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. - [Pair Programming with TDD videos](https://www.artofunittesting.com/pairing-videos.md): Videos of Roy Osherove pair programming and test-driving a Go game engine with Raymond Lim. - [Services and Pricing](https://www.artofunittesting.com/services-and-pricing.md): Roy Osherove consults and trains teams on unit testing, TDD, refactoring, continuous delivery and team metrics: on-site training, coaching, remote test reviews and public training. - [Testimonials](https://www.artofunittesting.com/testimonials.md): What developers say about Roy Osherove's unit testing and TDD workshops. - [Contact](https://www.artofunittesting.com/contact.md): Contact Roy Osherove about unit testing and TDD workshops, coaching and test reviews. --- title: "The Art of Unit Testing, 3rd Edition" url: "https://www.artofunittesting.com/art-of-unit-testing-3rd-edition.md" canonical: "https://www.artofunittesting.com/art-of-unit-testing-3rd-edition" tags: [] author: "Roy Osherove" description: "The Art of Unit Testing, Third Edition, by Roy Osherove (Manning): mocks, stubs and dependency injection in functional, modular and object oriented style, with examples in JavaScript." 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/" --- # The Art of Unit Testing, 3rd Edition The book · with examples in JavaScript This expanded edition teaches mocks, stubs and dependency injection in functional, modular and object oriented style. [![Cover of The Art of Unit Testing, Third Edition, by Roy Osherove (Manning)](https://www.artofunittesting.com/img/c/cover-400.jpg)](https://go.osherove.com/aout3) [The Art of Unit Testing, Third Edition (opens in a new tab)](https://go.osherove.com/aout3) updates an international bestseller to reflect modern development tools and practices. You’ll explore test patterns and organization, working with legacy code, and even “untestable” code. The many tool-agnostic examples are presented in JavaScript, and are carefully designed so that they apply to code written in any language. [Buy the book (opens in a new tab)](https://go.osherove.com/aout3) [Free resources](https://www.artofunittesting.com/#resources) Print + ebook from Manning · Buy links go to Manning and include Roy’s affiliate code. --- title: "Choose Your Language: TDD workshops" url: "https://www.artofunittesting.com/languages.md" canonical: "https://www.artofunittesting.com/languages" tags: [] author: "Roy Osherove" description: "Hands-on unit testing and TDD workshops by Roy Osherove in C#, modern JavaScript, Java (JUnit 5) 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/" --- # Choose Your Language: TDD workshops Workshops # Choose your language Three-day, hands-on unit testing and TDD workshops with Roy Osherove. - ![](https://www.artofunittesting.com/img/c/csharp.png) 3-day hands-on workshop ## [TDD & Unit Testing in C#](https://www.artofunittesting.com/tdd-in-c) Learn how to write your first test with NUnit or XUnit, learn about mocks, stubs and fakes with isolation frameworks such as FakeItEasy & NSubstitute, and refactor legacy code so you can test it easily. - ![](https://www.artofunittesting.com/img/c/js.png) 3-day hands-on workshop ## [TDD & Unit Testing in Modern JS](https://www.artofunittesting.com/tdd-in-js) Learn to write unit tests for async and observable code, as well as methods of faking functions, modules and other types of dependencies. You’ll explore test patterns and organization, working with legacy code, and even “untestable” code. - ![](https://www.artofunittesting.com/img/c/java.png) 3-day hands-on workshop ## [TDD in Java with JUnit 5](https://www.artofunittesting.com/tdd-in-java) Learn about the practices of TDD, and use JUnit 5 to test-drive new functionality. On the way you’ll learn about readability, maintainability & trustworthy tests. - ![](https://www.artofunittesting.com/img/c/kotlin.png) 3-day hands-on workshop ## [TDD in Kotlin](https://www.artofunittesting.com/tdd-in-kotlin) Start learning the skills of unit testing and TDD in Kotlin with Kotlin-Test, JUnit 5 & mockk. Want one for your team? [Get in touch](https://forms.gle/jQSx5KoXvrVA1JCK7) or see [all services](https://www.artofunittesting.com/services-and-pricing). --- title: "TDD & Unit Testing in C# workshop" url: "https://www.artofunittesting.com/tdd-in-c.md" canonical: "https://www.artofunittesting.com/tdd-in-c" 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 C\# workshop Hands-on workshop · 3 days · with Roy Osherove # The Art of Unit Testing & TDD in C# ![](https://www.artofunittesting.com/img/c/csharp.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 **C#,XUnit, NUnit** 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 C# on any platform - 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 NUnit APIs, test runners, tips and tricks 4. Writing readable tests 5. Test Driven Development Introduction 6. String Calculator Kata Exercises 7. Value based, 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. Interaction Test Exercises with Hand Written Fakes 4. Legacy Extract & override Techniques ### Day 3: Diving Deeper (09:00-16:00) 1. Isolation Frameworks: Constrained and Unconstrained 2. Isolation Framework Comparisons (Rhino Mocks, Typemock, Moq, FakeItEasy, NSubstitute) 3. Exercises 4. Unit Testing Best Practices 5. Code Review 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) --- title: "TDD & Unit Testing in Modern JavaScript workshop" url: "https://www.artofunittesting.com/tdd-in-js.md" canonical: "https://www.artofunittesting.com/tdd-in-js" 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 Modern JavaScript workshop Hands-on workshop · 3 days · with Roy Osherove # The Art of Unit Testing & TDD in Modern JavaScript ![](https://www.artofunittesting.com/img/c/js.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 **Specifically designed for the new age of modern JavaScript in 2020**, In this coding-packed training 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 Javascript and node.js, 2. Learn how to refactor code, and SOLID design concepts. 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, spies & fakes, and the difference between them 6. Learn about testing frameworks such as jest and Jasmine, and isolation (mocking) frameworks like sinon & jest mocks. ## Pre-Requisites - The course will benefit both backend (node.js) developers and frontend (Angular, React, Vue etc..) developers with at least a year’s experience developing with [JavaScript ES2015 syntax knowledge](https://github.com/lukehoban/es6features#readme) - No knowledge of typescript is required, but drills can be executed in typescript if you find it useful. - VS Code, IntelliJ, Webstorm or other JS enabled IDEs with JavaScript or Typescript enabled plugins - JS [ES2015 syntax](https://github.com/lukehoban/es6features#readme) knowledge ## Agenda ### Day 1: Beginnings (09:00-16:00) 1. Units, entry points & exit points. 2. The first unit test & a continuous testing environment 3. Jest basics & Drills 4. Writing readable, maintainable tests 5. Test Driven Development Introduction 6. String Calculator,Password Verifier Kata Drills 7. Value based, State Based and Interaction Based Tests 8. Drills ### Day 2: Mocks & Stubs (09:00-16:00) 1. Understanding Fakes, Spies Mocks and Stubs 2. Hand Written Fakes, Stubs and Mocks 3. Faking Time & Drills 4. Faking other dependencies & Drills 5. Jest.fn, jest.spyOn and other creatures 6. Drills, Drills, Drills ### Day 3: Diving Deeper (09:00-16:00) 1. Async in Tests & Drills 2. Legacy Refactorings 3. Faking whole modules & Drills 4. Unit Testing Good Practices 5. Code Review Drills ## 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) --- 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) --- title: "TDD & Unit Testing in Kotlin workshop" url: "https://www.artofunittesting.com/tdd-in-kotlin.md" canonical: "https://www.artofunittesting.com/tdd-in-kotlin" 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 Kotlin workshop Hands-on workshop · 3 days · with Roy Osherove # The Art of Unit Testing & TDD in Kotlin ![](https://www.artofunittesting.com/img/c/kotlin.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 **Kotlin, JUnit 5, Kotlin-Test, mockk** 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 Kotlin - The course will mainly target **Kotlin-JVM** projects, but any kotlin target should be able to get value of out of this training - IntelliJ with Kotlin support 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 **JUnit5 & Kotlin-Test** APIs, test runners, tips and tricks 4. Assertion Frameworks 5. Writing readable tests 6. Test Driven Development Introduction 7. String Calculator + Password Verifier Kata Exercises 8. Value based, 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: **mockk** 4. Exercises 5. Unit Testing Best Practices 6. Code Review Exercises ### Day 3: Diving Deeper (09:00-16:00) 1. Refactoring Exercises: 1. Faking Time 2. Extract And Override 3. Introduce Instance Delegator 2. Exercises 3. Reviewing tests from your own code 4. Writing tests on your own production code (if time permits) ## 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) --- title: "Definition of a Unit Test" url: "https://www.artofunittesting.com/definition-of-a-unit-test.md" canonical: "https://www.artofunittesting.com/definition-of-a-unit-test" 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/" --- # Definition of a Unit Test Article · Free resource # Unit test: a definition > Related: [Test Review Guidelines](https://www.artofunittesting.com/unit-testing-review-guidelines/) I used to feel that a ‘unit’ was the smallest possible part of a code base (a method, really). But in the past couple of years I’ve changed my mind. Here’s how I define a unit test, as of October 2011: **A unit test is an automated piece of code that invokes a unit of work in the system _and then checks a single assumption about the behavior of that unit of work_**. A unit of work is a single logical functional use case in the system that can be invoked by some public interface (in most cases). A unit of work can span a single method, a whole class or multiple classes working together to achieve one single logical purpose that can be verified. **A good unit test is:** - Able to be fully **automated** - Has full control over all the pieces running (Use mocks or stubs to achieve this isolation when needed) - Can be run in any **order** if part of many other tests - Runs in **memory** (no DB or File access, for example) - **Consistently** returns the same result (You always run the same test, so no random numbers, for example. save those for integration or range tests) - Runs **fast** - Tests a **single logical concept** in the system - **Readable** - **Maintainable** - **Trustworthy** (when you see its result, you don’t need to debug the code just to be sure) I consider any test that doesn’t live up to all these as an integration test and put it in its own “integration tests” project. ## Go deeper: the book The Art of Unit Testing, 3rd Edition covers these ideas in depth, with examples in JavaScript. [Buy the book (opens in a new tab)](https://go.osherove.com/aout3) Print + ebook from Manning · Buy links go to Manning and include Roy’s affiliate code. --- title: "Test Review Guidelines" url: "https://www.artofunittesting.com/unit-testing-review-guidelines.md" canonical: "https://www.artofunittesting.com/unit-testing-review-guidelines" 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/" --- # Test Review Guidelines Checklist · Free resource # How to do test reviews > Related: [Definition of a unit test](https://www.artofunittesting.com/definition-of-a-unit-test/) ### Summary Test Reviews (like code reviews, but on tests) can offer you the best process for teaching and improving the quality of your code and your unit tests while implementing unit testing into your organization. Review EVERY piece of unit testing code, and use the following points as a simple check list of things to watch out for. (you’ll find this is mainly useful when working in statically types languages such as Java or C#). > **You can find these guidelines and more on the last page of the book.** (but this page contains additions not found in the book) ### Readability - Make sure setup and teardown methods are not abused. **It’s better to use factory methods** for readability (p. 188, 214) - Make sure the test **tests one thing only** (p. 179) - Check for good and consistent **naming conventions** (p. 210-211) - Make sure that only **meaningful assert messages** are used, or none at all (meaningful test names are better) (p. 212) - Make sure **asserts are separated from actions** (different lines). (p. 214) - Make sure tests don’t use **magic strings and values as inputs**. use the simplest inputs possible to prove your point. - Make sure there is consistency in location of tests. make it **easy to find related tests** for a method, or a class, or a project. ### Maintainability - Make sure tests are **isolated from each other and repeatable** (p. 191) - Make sure that testing private or protected methods is not the norm (**public is always better**) (P. 182) - Make sure tests are not **over-specified** (p. 205) - Make sure that **state-based testing is preferred** over using interaction testing (p. 83) - Make sure **strict mocks are used as little as possible** (leads to over specification and fragile tests) (p. 106) - Make sure there is no more than **one mock per test** (p. 94) - Make sure tests do not **mix mocks and regular asserts** in the same test (testing multiple things) - Make sure that tests **‘verify’ mock calls only on the single mock** object in the test, and not on all the fake objects in the tests (the rest are stubs, this leads to over specification and fragile tests) (p.123) - Make sure the test verifies only on a **single call to a mock object**. Verifying multiple calls on a mock object is either over specification or testing multiple things. - Make sure that only in very rare cases **a mock is also used as a stub** to return a value in the same test (p. 84) ### Trust - Make sure the test does not contain **logic or dynamic values** (p. 178) - **Check coverage** by playing with values (booleans or consts) (p. 180) - Make sure unit tests are **separated from integration tests** (p. 180) - Make sure tests don’t use things that keep changing in a unit test (like DateTime.Now ). **Use fixed values**. - Make sure tests don’t assert with expected values that are created dynamically - you might be **repeating production code.** ## Go deeper: the book The Art of Unit Testing, 3rd Edition covers these ideas in depth, with examples in JavaScript. [Buy the book (opens in a new tab)](https://go.osherove.com/aout3) Print + ebook from Manning · Buy links go to Manning and include Roy’s affiliate code. --- title: "Pair Programming with TDD videos" url: "https://www.artofunittesting.com/pairing-videos.md" canonical: "https://www.artofunittesting.com/pairing-videos" tags: [] author: "Roy Osherove" description: "Videos of Roy Osherove pair programming and test-driving a Go game engine with Raymond Lim." 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/" --- # Pair Programming with TDD videos Videos · Free resource # Pairing with TDD videos This page contains videos of me doing pair programming and TDD with other people. ## Building a Go Game Engine with Raymond Lim [Here is how this all started](https://osherove.com/blog/2012/6/25/video-part-1-building-a-go-game-engine-with-tdd-and-pair-pro.html). Now, Raymond and I pair program and tdd a Go Game engine. See what it feels like to do something a little more complicated than a book sample. Several good hours of video here. 1. S1Session 1 ### [Diving right in (blog post, opens in a new tab)](https://osherove.com/blog/2012/6/25/video-part-1-building-a-go-game-engine-with-tdd-and-pair-pro.html) - [![](https://www.artofunittesting.com/img/yt/xX9hfPkA800.jpg) TDD Pairing Session 1 with Raymond Lim and Roy Osherove Watch on YouTube ↗ (opens in a new tab)](https://www.youtube.com/watch?v=xX9hfPkA800) 2. S2Session 2 ### Session 2 (three parts) - [![](https://www.artofunittesting.com/img/yt/fCgCp4Bc-Sc.jpg) Session 2a: A Go Game Engine with Raymond Lim Watch on YouTube ↗ (opens in a new tab)](https://www.youtube.com/watch?v=fCgCp4Bc-Sc) - [![](https://www.artofunittesting.com/img/yt/odHtISznxIA.jpg) Session 2b: Go Engine Watch on YouTube ↗ (opens in a new tab)](https://www.youtube.com/watch?v=odHtISznxIA) - [![](https://www.artofunittesting.com/img/yt/BkUzoWnGTYM.jpg) Session 2c: Go Game Engine with Raymond Lim Watch on YouTube ↗ (opens in a new tab)](https://www.youtube.com/watch?v=BkUzoWnGTYM) 3. S3Session 3 ### [Plowing ahead with finding a winner (blog post, opens in a new tab)](https://osherove.com/blog/2012/6/28/video-part-3-building-a-go-game-engine-with-tdd-and-pair-pro.html) - [![](https://www.artofunittesting.com/img/yt/iy6RcqfAFyY.jpg) TDD and pairing session 3: Go Engine Watch on YouTube ↗ (opens in a new tab)](https://www.youtube.com/watch?v=iy6RcqfAFyY) 4. S4Session 4 ### [A Refactoring Dilemma (blog post, opens in a new tab)](https://osherove.com/blog/2012/6/29/refactoring-dillema-video-part-4-building-a-go-game-engine-w.html) - [![](https://www.artofunittesting.com/img/yt/_s_lBh315Tc.jpg) TDD Pairing Session 4: Go Game Engine Watch on YouTube ↗ (opens in a new tab)](https://www.youtube.com/watch?v=_s_lBh315Tc) 5. S5Session 5 ### [Building A Test DSL for the Go Board (blog post, opens in a new tab)](https://osherove.com/blog/2012/7/2/video-part-5-a-test-dsl-go-game-engine-with-tdd-and-pair-pro.html) - [![](https://www.artofunittesting.com/img/yt/7d0TvjrgxnY.jpg) TDD Pairing Session 5: A Test DSL Watch on YouTube ↗ (opens in a new tab)](https://www.youtube.com/watch?v=7d0TvjrgxnY) 6. S6Session 6 ### [Total N00b Mistakes (blog post, opens in a new tab)](https://osherove.com/blog/2012/7/5/video-part-6-total-n00b-mistakes-go-game-engine-with-tdd-and.html) - [![](https://www.artofunittesting.com/img/yt/mEpj4g68TQ8.jpg) TDD Pairing Session 6: Total Noob Fail Watch on YouTube ↗ (opens in a new tab)](https://www.youtube.com/watch?v=mEpj4g68TQ8) 7. S7a + bSession 7a + b ### [The bug that wouldn’t die · Finally, something is moving along (blog post, opens in a new tab)](https://osherove.com/blog/2012/7/9/video-part-7-the-bug-that-wouldnt-die-go-game-engine-with-td.html) - [![](https://www.artofunittesting.com/img/yt/svhfTVX_T7U.jpg) Session 7a: More debugging! Watch on YouTube ↗ (opens in a new tab)](https://www.youtube.com/watch?v=svhfTVX_T7U) - [![](https://www.artofunittesting.com/img/yt/7kRE_4a0dAQ.jpg) Session 7b: Finally some new features Watch on YouTube ↗ (opens in a new tab)](https://www.youtube.com/watch?v=7kRE_4a0dAQ) 8. S8Session 8 ### [The Big Refactoring (blog post, opens in a new tab)](https://osherove.com/blog/2012/7/13/video-part-8-the-big-refactoring-tdd-pairing-a-go-game-engin.html) - [![](https://www.artofunittesting.com/img/yt/YdooYM1Gc2Q.jpg) TDD Pairing Session 8: The Big Refactor Watch on YouTube ↗ (opens in a new tab)](https://www.youtube.com/watch?v=YdooYM1Gc2Q) --- title: "Services and Pricing" url: "https://www.artofunittesting.com/services-and-pricing.md" canonical: "https://www.artofunittesting.com/services-and-pricing" tags: [] author: "Roy Osherove" description: "Roy Osherove consults and trains teams on unit testing, TDD, refactoring, continuous delivery and team metrics: on-site training, coaching, remote test reviews and public training." 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/" --- # Services and Pricing Work with Roy # Services by Roy Osherove ![Roy Osherove](https://www.artofunittesting.com/img/author/roy-osherove-2026-photo-480.jpg) I’m the [founder of Legato Labs](https://legatohq.com/), author of [The Art of Unit Testing](https://www.artofunittesting.com/) and also created the [String Calculator Kata](https://osherove.com/tdd-kata-1). I consult & train teams on various engineering practices & related topics such as: - [Unit Testing & Test Driven Development](https://www.artofunittesting.com/languages) - Refactoring & Clean Code - Continuous Delivery, pipelines & visibility dashboards - Team Metrics & KPIs such as cycle time, [Mean time to Recovery](https://web.archive.org/web/20181212105306/http://enterprisedevops.org/article/devops-metric-mean-time-to-recovery-mttr-definition-and-reasoning "Archived copy (Wayback Machine)"), Escaped Bugs, Red-To-Green time, Main-Merge-Time and more. - 01[On-Site Training (opens in a new tab)](https://osherove.com/trainingoptions) - 02On-Site Coaching/Consulting/Pairing - 03Remote Test Reviews - 04Public Training [Book a service](https://forms.gle/jQSx5KoXvrVA1JCK7) --- title: "Testimonials" url: "https://www.artofunittesting.com/testimonials.md" canonical: "https://www.artofunittesting.com/testimonials" tags: [] author: "Roy Osherove" description: "What developers say about Roy Osherove's unit testing and TDD workshops." 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/" --- # Testimonials From workshop attendees > Rarely are subject experts also great teachers, Roy is the whole package. Blake RhodesSoftware Engineer > Very exciting course with precise balance between theory and practice. Roy is an extremely good listener making me not hesitate to get all the answers I need in a very clear way. Even if you have experience with TDD, I highly recommend his TDD Mastery Training. Diego FariaSoftware Engineer > Roy is an excellent speaker with a good pace on his course. I will definitely implement what I learn. Marcio Carneiroreis > Perfect course, liked the content and educational guidance! Recommend it highly! Marco Pasopas > Great course for junior/mid level specialists wanting to start changing their thinking to TDD way of thinking. Aleksandras Gavinciuk [Explore the workshops](https://www.artofunittesting.com/languages) --- title: "Contact" url: "https://www.artofunittesting.com/contact.md" canonical: "https://www.artofunittesting.com/contact" tags: [] author: "Roy Osherove" description: "Contact Roy Osherove about unit testing and TDD workshops, coaching and test reviews." 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/" --- # Contact Workshops · services · questions # Contact Roy Book a workshop, ask about on-site training, coaching or remote test reviews, or just say hello. Messages go through a short contact form (Google Forms) and reach Roy privately. [Open the contact form (opens in a new tab)](https://forms.gle/jQSx5KoXvrVA1JCK7)