Javascript Unit Testing - What is Unit Testing and TDD?

Javascript Unit Testing - What is Unit Testing and TDD?

Information drawn from

A unit test runs some code over a segment of your program checking the input and output. These tests allow developers to check individual areas of a program to see where (and why) errors occur.

This comes with an inherent understanding of what you’re trying to test for and how the code should function.

Every developer knows we should write unit tests in order to prevent defects from being deployed to production.

Why Bother with Test Discipline?

Your tests are your first and best line of defense against software defects. Your tests are more important than linting & static analysis (which can only find a subclass of errors, not problems with your actual program logic). Tests are as important as the implementation itself (all that matters is that the code meets the requirement — how it’s implemented doesn’t matter at all unless it’s implemented poorly).

Unit tests combine many features that make them your secret weapon to application success:

Unit tests don’t need to be twisted or manipulated to serve all of those broad-ranging goals. Rather, it is in the essential nature of a unit test to satisfy all of those needs. These benefits are all side-effects of a well-written test suite with good coverage.

The Science of TDD

Test-driven development (TDD) is a software development process that relies on the repetition of a very short development cycle:

This is opposed to software development that allows code to be added that is not proven to meet requirements.

The evidence says:

Says science: There is significant empirical evidence that TDD works.

Write Tests First

Studies from Microsoft Research, IBM, and Springer tested the efficacy of test-first vs test-after methodologies and consistently found that a test-first process produces better results than adding tests later. It is resoundingly clear: Before you implement, write the test.

Before you implement,write the test.

How unit tests are used


Last update on 29 Nov 2021