1 The basics of unit testing

This chapter covers

  • Defining entry points & exit points
  • Defining a unit of work & unit tests
  • Contrasting unit testing with integration testing
  • Exploring a simple unit testing example
  • Understanding test-driven development
Some assumptions before we begin:

You already know basic usage of NODE.JS and node package manager (NPM). You know how to use GIT source control. You’ve seen github.com before and you know how to clone a repository from there. You’ve written code in JavaScript , either backend or frontend code, and you can understand basic ES6 JavaScript code examples

Can you use this book for non JavaScript use?

Yes. The previous editions of this book were in C#. I’ve foun that about 80% of the patterns there have transferred over quite easily. So you should be able to read this book eve if you come from Java, .NET, Python, Ruby or other languages. The patterns are just patterns. The language being used is there just so we can demonstrate those patterns. But they are not language specific.

1.1   The first step

There’s always a first step: the first time you wrote a program, the first time you failed a project, and the first time you succeeded in what you were trying to accomplish. You never forget your first time, and I hope you won’t forget your first tests.

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