Welcome to Manning India!

We are pleased to be able to offer regional eBook pricing for Indian residents.
All eBook prices are discounted 40% or more!
The Art of Unit Testing, Third Edition
with JavaScript examples
Roy Osherove
  • MEAP began December 2019
  • Publication in Spring 2021 (estimated)
  • ISBN 9781617297489
  • 325 pages (estimated)
  • printed in black & white
free previous edition eBook included
An eBook copy of the previous edition of this book is included at no additional cost. It will be automatically added to your Manning Bookshelf within 24 hours of purchase.

A book that is seeing a third release must be awesome and this book certainly is.

Sander Zegveld
The Art of Unit Testing, Third Edition updates an international bestseller to reflect modern development tools and practices. This expanded edition teaches you to write unit tests for async and observable code, as well as methods of faking functions, modules and refactorings. 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.
Table of Contents detailed table of contents

Part 1: Getting started

1 The basics of unit testing

1.1 The first step

1.2 Defining unit testing, step by step

1.3 Entry Points & Exit Points

1.4 Exit Point Types

1.5 Different Exit Points, Different Techniques

1.6 A Test from Scratch

1.7 Characteristics of a good unit test

1.7.1 So, what’s a “good” unit test?

1.7.2 A simple checklist

1.8 Integration tests

1.8.1 Drawbacks of integration tests compared to automated unit tests

1.9 Finalizing our definition

1.10 What About Regression Tests?

1.11 Test-driven development

1.12 Three core skills needed for successful TDD

1.13 Summary

2 A first unit test

2.1 About Jest

2.1.1 Preparing our environment

2.1.2 Preparing our working folder

2.1.3 Installing Jest

2.1.4 Creating a test file

2.1.5 Executing Jest:

2.2 The Library, the Assert, the Runner & the Reporter

2.3 What unit testing frameworks offer

2.3.1 The xUnit frameworks

2.3.2 XUnit, TAP and Jest Structures

2.4 Introducing the Password Verifier Project

2.5 The first Jest test for verifyPassword

2.5.1 Testing the test

2.5.2 U.S.E Naming

2.5.3 String comparisons and maintainability

2.5.4 Using describe()

2.5.5 Structure can imply context

2.5.6 The ‘It’ function

2.5.7 Two Jest Flavors

2.5.8 Refactoring the Production Code

2.6 Trying the beforeEach() route

2.6.1 beforeEach() and scroll fatigue

2.7 Trying the factory method route

2.7.1 Replacing beforeEach() completely with factory methods.

2.8 Going Full Circle to test()

2.9 Refactoring to parameterized tests

2.10 Checking for expected thrown errors

2.11 Setting Test Categories

2.12 Summary

Part 2: Core techniques

3 Using stubs to break dependencies

4 Interaction testing using mock objects

5 Isolation (mocking) frameworks

6 Digging deeper into isolation frameworks

Part 3: The test code

7 Test hierarchies and organization

8 The pillars of good unit tests

Part 4: Design and process

9 Integrating unit testing into the organization

10 Working with legacy code

11 Design and testability

About the Technology

Unit testing is a universally-adopted practice on dev teams of all sizes. Great developers will tell you that testing is as much a state of mind as a collection of tools and practices. The Art of Unit Testing, Third Edition takes you below the surface and understand how unit testing can transform the way you deliver and maintain software. Now with examples in JavaScript, this new edition has been updated to reflect the characteristics of a modern codebase, including async and modularized, distributed services. The practices and patterns you’ll learn can also be easily applied to other languages, including C#, Java, and Python.

About the book

The Art of Unit Testing, Third Edition guides you step by step from your first simple unit tests to building complete test sets that are maintainable, readable, and trustworthy. Now with examples using JavaScript and Node, this expanded third edition teaches you to write unit tests for async and observable code, as well as methods of faking functions, modules and refactorings. You’ll get to grips with complex subjects such as mocks and stubs, explore how to handle tricky legacy codebases, and save yourself time with tests that function for both frontend and backend applications. The Art of Unit Testing, Third Edition is an essential guide for any unit tester who wants to feel confident writing code that’s easier to create, maintain, and adapt.

What's inside

  • Creating readable, maintainable, and trustworthy tests
  • Working with fakes, stubs, mock objects, and isolation (mocking) frameworks
  • Simple dependency injection techniques
  • Refactoring legacy code

About the reader

The examples in the book use JavaScript and Node and cover the full dev stack.

About the author

Roy Osherove is an internationally-recognized expert in unit testing and agile software methodology. Still an active coder, he consults and trains teams worldwide on the gentle art of unit testing and test-driven development. He is also the author of Elastic Leadership (Manning 2016). Roy’s blog is at ArtOfUnitTesting.com.

Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
MEAP combo $49.99 pBook + eBook + liveBook
includes previous edition eBook
MEAP eBook $39.99 pdf + ePub + kindle + liveBook
includes previous edition eBook
Prices displayed in rupees will be charged in USD when you check out.

placing your order...

Don't refresh or navigate away from the page.

FREE domestic shipping on three or more pBooks