You can download the source files for the book from http://pragprog.com/titles/lotdd/source_code. The examples are grouped by chapter.
Much of what you will learn about TDD involves incrementally growing code. As such, the examples you’ll see within each chapter present incremental versions of the code. The versions correspond to numbered subdirectories (1, 2, 3, ...) within the directory for the chapter. For example, the first code snippet in Chapter 2, Test-Driven Development: A First Example is c2/1/SoundexTest.cpp; it shows the first version of the file SoundexTest.cpp. The second version appears as c2/2/SoundexTest.cpp.
You can also find the example code at GitHub (https://github.com/jlangr). At GitHub, you will find a repository for each relevant book chapter. For example, the repository named c2 corresponds to the Soundex example built in the second chapter of the book.
The version number for a given code snippet shown in the book corresponds to a branch within a GitHub repository. For example, you can find code for the listing c5/4/PlaceDescriptionService.cpp in the file PlaceDescriptionService.cpp in the branch named 4 in the c5 repository.
Within each version directory you will find the necessary source, including a main function to run tests and a CMake build script. You will need to install and configure a few tools to run any examples. Some examples require the installation of additional third-party libraries.
You will need a C++11-compliant compiler and make utility in order to build the examples. Most require Google Mock as the unit testing tool. Examples from three chapters use another unit testing tool named CppUTest.
You might want to change the source distribution to support other compilers (or pre-C++11 compilers), incorporate a different build tool, or use a different unit testing tool. Fortunately, most of the example codebases are small, with the exception of the library code used in the Chapter 7, Quality Tests chapter.
The following table identifies the subdirectory, unit testing tool, and additional third-party libraries required for the examples in each chapter.
Chapter | Directory | Unit Testing Tool | Third-Party Libraries |
---|---|---|---|
Chapter 2, Test-Driven Development: A First Example | c2 | Google Mock | None |
Chapter 3, Test-Driven Development Foundations | c3 | Google Mock | None |
Chapter 4, Test Construction | c3 | Google Mock | None |
Chapter 5, Test Doubles | c5 | Google Mock | cURL, JsonCpp |
Chapter 6, Incremental Design | c6 | Google Mock | Boost (gregorian) |
Chapter 7, Quality Tests | c7 | Google Mock | Boost (gregorian, algorithm, assign) |
Chapter 8, Legacy Challenges | wav | CppUTest | rlog, Boost (filesystem) |
Chapter 9, TDD and Threading | c9 | CppUTest | None |
Chapter 10, Additional TDD Concepts and Discussions | tpp | CppUTest | None |
Appendix 2, Code Kata: Roman Numeral Converter | roman | Google Mock | None |
3.142.173.238