Test-Driven Development with C++
A simple guide to writing bug-free Agile code
Abdul Wahid Tanner
BIRMINGHAMMUMBAI
Test-Driven Development with C++
Copyright 2022 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author(s), nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Group Product Manager: Gebin George
Publishing Product Manager: Kunal Sawant
Senior Editor: Nithya Sadanandan
Technical Editor: Jubit Pincy
Copy Editor: Safis Editing
Project Coordinator: Deeksha Thakkar
Proofreader: Safis Editing
Indexer: Rekha Nair
Production Designer: Shyam Sundar Korumilli
Developer Relations Marketing Executive: Sonakshi Bubbar
First published: October 2022
Production reference: 1211022
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-80324-200-2
www.packt.com
Focus on constant improvement
Abdul Wahid Tanner
Contributors
About the author
I'm Abdul Wahid Tanner and have been programming C++ since 1992 and teaching others how to code for almost as long. I first became interested in TDD around 2005 and decided to implement a board game that I liked playing using strict TDD. At the time, I was using C# and a test framework that was able to find and run the tests. It wasn't until about 2014 that I decided to see whether I could use C++ and TDD together. There were many choices for tools that helped run C++ tests, but they were big and full of features. I wanted something small and simple, so I wrote a unit test library in about 650 lines of code. The code in this book is a complete and better rewrite of that early code. I hope you find the code in this book useful and decide to use it in your projects. However, even if you decide to use one of the commercial tools, you should still benefit from the understanding that this book provides about how the tools work and how to follow the TDD process.
About the reviewer
Serban Stoenescu is a software developer specializing in C++. He is currently working for Everseen on some projects that require OpenCV and some machine learning. In the past he has worked for SkAD Labs on a CAD project with OpenCASCADE, Atigeo on Big Data projects in Java, and Alcatel-Lucent (now part of Nokia). At Alcatel-Lucent, he was also a trainer, teaching Rational ROSE. He is the co-author of Towards the Impact of Design Flaws on the Resources Used by an Application, a paper at ARMS-CC 2014. Currently, he is also a Udemy instructor, his most popular course being C++ Unit Testing: Google Test and Google Mock. His other courses are CMake from Zero to Hero and C++ Machine Learning Algorithms Inspired by Nature.
Preface
Many years ago, I started avoiding cookbook-style books when I wanted to learn a new technology or develop a new skill. A book should guide us to understand fundamental ideas so we can adapt our learning to fit our needs. We should not get lost just because a recipe doesnt match exactly what we want to accomplish.
I also tend to avoid books that are full of theory. You probably know what I mean. Instead of explaining how to use a technology, these books mention ideas with no exploration of putting the ideas into practice. Focusing on either one of these two tangents can leave the learning experience incomplete.