Cover page by Graham Lee

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

3. How to Write a Unit Test

You’ve now seen what we’re trying to achieve by testing software, and how test-driven software and unit tests can help to achieve that. But how exactly is a unit test written? In this chapter you’ll see a single unit test being built from first principles. You’ll see what the different components of a test are, and how to go from a test or collection of tests to production code. The code in this chapter is not part of a project: It just shows the thought process in going from requirement to tested app code. You do not need to run the code in this chapter.

The Requirement

Remember, the first step in writing a unit test is to identify what the application needs to do. After I know what I need, I can decide what code ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required