Externally indexed torrent
If you are the original uploader, contact staff to have it moved to your account
Textbook in PDF format
Learn to write better automated tests that will dramatically increase your productivity and have fun while doing so. This book is a build-your-own adventure designed for individual reading and for collaborative workshops.
You will build an xUnit automated test framework using JavaScript: initially a clone of Jest, but adding a couple of neat features borrowed from RSpec, the genre-defining tool for behavior-driven development (BDD). Along the way, you will explore the philosophy behind automated testing best practices. The automated test runner is one of the most important innovations within software engineering. But for many programmers, automated testing remains a mystery, and knowing how to write good tests is akin to sorcery.
This book is a follow-along practical exercise in building an automated unit test framework, written in the JavaScript language and running on the Node platform. You can think of it as a less functional replacement for well-known packages like Jest, Mocha, Jasmine, and Vitest.
The framework is called concise-test, and it takes the form of an NPM package that you’ll start building in Chapter 1. The book also makes use of a package named todo-example, which is a sample application that will make use of concise-test, as a package dependency.
By the end of Chapter 1, you’ll be able to run the command npm test in your todo-example project directory and have your test runner execute the application test scripts.
Do I Need to Know JavaScript? You’ll need to know modern JavaScript syntax to use this book, including arrow functions, destructuring assignments, and rest parameters. It also uses ECMAScript Modules for importing and exporting values. That being said, don’t stop reading if you don’t know any JavaScript as long as you have experience in at least one programming language, you should be able to pick it up as we go along. If you’re unsure what some of the syntax means, take a moment to stop and look it up online. JavaScript is a wonderfully flexible language. It is dynamic and functional at its core, but also has support for objects in a rather unique way, which is empowering.
The beauty of unit testing is that it is universally applicable to all mainstream programming languages, so if you were really keen, you could rebuild all of the same code in your own favorite language. The only chapters that are directly related to JavaScript are Chapters 9 and 17.
As the chapters of this book unfold, you will see how the humble test runner is an elegant and simple piece of software. Each chapter picks a single feature to build, like the "it" function or the "beforeEach" block. It picks apart the theory of why the feature needs to exist, and how to use it effectively in your own test suites. Every chapter ends with a set of ideas for extension points should you wish to explore further, alone or in groups. The book culminates in an implementation of test doubles and mocks?one of the most difficult and misunderstood concepts within automated testing.
By the end of the book, you will have gained a solid understanding of automated testing principles that you can immediately apply to your work projects.
What You'll Learn:
Build an xUnit automated test framework
See how an automated test runner works
Understand the best practices for automated unit testing
Effectively use test doubles and mocks
Who This Book Is For:
Software developers with JavaScript experience who are seeking to master the art of automated testing.
Introduction
Part I: Building the Core of a Test Framework
Chapter 1: Creating a Barebones Test Runner
Chapter 2: Building a Function to Represent a Test Case
Chapter 3: Grouping Tests
Chapter 4: Promoting Conciseness with Shared Setup and Teardown
Chapter 5: Improving Legibility with Expectations and Matchers
Part II: Constructing a Usable Framework
Chapter 6: Formatting Expectation Errors
Chapter 7: Automatically Discovering Test Files
Chapter 8: Focusing on Specific Tests
Chapter 9: Supporting Asynchronous Tests
Chapter 10: Reporting
Part III: Extending for Power Users
Chapter 11: Shared Examples
Chapter 12: Tagging Tests
Chapter 13: Skipping Tests
Part IV: Test Doubles and Module Mocks
Chapter 15: Deep Equality and Constraining Matchers
Chapter 16: Test Doubles
Chapter 17: Module Mocks