O'Reilly logo

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

Modern C++ Programming with Test-Driven Development

Book Description

If you program in C++ you've been neglected. Test-driven development (TDD) is a modern software development practice that can dramatically reduce the number of defects in systems, produce more maintainable code, and give you the confidence to change your software to meet changing needs. But C++ programmers have been ignored by those promoting TDD--until now. In this book, Jeff Langr gives you hands-on lessons in the challenges and rewards of doing TDD in C++.

Modern C++ Programming With Test-Driven Development, the only comprehensive treatment on TDD in C++ provides you with everything you need to know about TDD, and the challenges and benefits of implementing it in your C++ systems. Its many detailed code examples take you step-by-step from TDD basics to advanced concepts. As a veteran C++ programmer, you're already writing high-quality code, and you work hard to maintain code quality. It doesn't have to be that hard.

In this book, you'll learn:

how to use TDD to improve legacy C++ systems

how to identify and deal with troublesome system dependencies

how to do dependency injection, which is particularly tricky in C++

how to use testing tools for C++ that aid TDD

* new C++11 features that facilitate TDD

As you grow in TDD mastery, you'll discover how to keep a massive C++ system from becoming a design mess over time, as well as particular C++ trouble spots to avoid. You'll find out how to prevent your tests from being a maintenance burden and how to think in TDD without giving up your hard-won C++ skills. Finally, you'll see how to grow and sustain TDD in your team.

Whether you're a complete unit-testing novice or an experienced tester, this book will lead you to mastery of test-driven development in C++.

Table of Contents

  1. Modern C++ Programming with Test-Driven Development
  2. For the Best Reading Experience...
  3. Table of Contents
  4. Early Praise for Modern C++ Programming with Test-Driven Development
  5. Foreword
  6. Introduction
    1. But Can It Work for Me on My System?
    2. Who This Book Is For
    3. What You’ll Need
    4. How to Use This Book
    5. About “Us”
    6. About Me
    7. About the C++ Style in This Book
    8. Acknowledgments
    9. Dedication
  7. Chapter 1: Global Setup
    1. Setup
    2. The Examples
    3. C++ Compiler
    4. CMake
    5. Google Mock
    6. CppUTest
    7. libcurl
    8. JsonCpp
    9. rlog
    10. Boost
    11. Building Examples and Running Tests
    12. Teardown
  8. Chapter 2: Test-Driven Development: A First Example
    1. Setup
    2. The Soundex Class
    3. Getting Started
    4. Fixing Unclean Code
    5. Incrementalism
    6. Fixtures and Setup
    7. Thinking and TDD
    8. Test-Driving vs. Testing
    9. What If?
    10. One Thing at a Time
    11. Limiting Length
    12. Dropping Vowels
    13. Doing What It Takes to Clarify Tests
    14. Testing Outside the Box
    15. Back on Track
    16. Refactoring to Single-Responsibility Functions
    17. Finishing Up
    18. What Tests Are We Missing?
    19. Our Solution
    20. The Soundex Class
    21. Teardown
  9. Chapter 3: Test-Driven Development Foundations
    1. Setup
    2. Unit Test and TDD Fundamentals
    3. The TDD Cycle: Red-Green-Refactor
    4. The Three Rules of TDD
    5. Getting Green on Red
    6. Mind-Sets for Successful Adoption of TDD
    7. Mechanics for Success
    8. Teardown
  10. Chapter 4: Test Construction
    1. Setup
    2. Organization
    3. Fast Tests, Slow Tests, Filters, and Suites
    4. Assertions
    5. Inspecting Privates
    6. Testing vs. Test-Driving: Parameterized Tests and Other Toys
    7. Teardown
  11. Chapter 5: Test Doubles
    1. Setup
    2. Dependency Challenges
    3. Test Doubles
    4. A Hand-Crafted Test Double
    5. Improving Test Abstraction When Using Test Doubles
    6. Using Mock Tools
    7. Getting Test Doubles in Place
    8. Design Will Change
    9. Strategies for Using Test Doubles
    10. Miscellaneous Test Double Topics
    11. Teardown
  12. Chapter 6: Incremental Design
    1. Setup
    2. Simple Design
    3. Where Is the Up-Front Design?
    4. Refactoring Inhibitors
    5. Teardown
  13. Chapter 7: Quality Tests
    1. Setup
    2. Tests Come FIRST
    3. One Assert per Test
    4. Test Abstraction
    5. Teardown
  14. Chapter 8: Legacy Challenges
    1. Setup
    2. Legacy Code
    3. Themes
    4. The Legacy Application
    5. A Test-Driven Mentality
    6. Safe Refactoring to Support Testing
    7. Adding Tests to Characterize Existing Behavior
    8. Sidetracked by the Reality of Legacy Code
    9. Creating a Test Double for rlog
    10. Test-Driving Changes
    11. A New Story
    12. A Brief Exploration in Seeking Faster Tests
    13. Mondo Extracto
    14. Spying to Sense Using a Member Variable
    15. Spying to Sense Using a Mock
    16. Alternate Injection Techniques
    17. Large-Scale Change with the Mikado Method
    18. An Overview of the Mikado Method
    19. Moving a Method via Mikado
    20. More Thoughts on the Mikado Method
    21. Is It Worth It?
    22. Teardown
  15. Chapter 9: TDD and Threading
    1. Setup
    2. Core Concepts for Test-Driving Threads
    3. The GeoServer
    4. Performance Requirements
    5. Designing an Asynchronous Solution
    6. Still Simply Test-Driving
    7. Ready for a Thready!
    8. Exposing Concurrency Issues
    9. Creating Client Threads in the Test
    10. Creating Multiple Threads in the ThreadPool
    11. Back to the GeoServer
    12. Teardown
  16. Chapter 10: Additional TDD Concepts and Discussions
    1. Setup
    2. TDD and Performance
    3. Unit Tests, Integration Tests, and Acceptance Tests
    4. The Transformation Priority Premise
    5. Writing Assertions First
    6. Teardown
  17. Chapter 11: Growing and Sustaining TDD
    1. Setup
    2. Explaining TDD to Nontechies
    3. The Bad Test Death Spiral, aka the SCUMmy Cycle
    4. Pair Programming
    5. Katas and Dojos
    6. Using the Code Coverage Metric Effectively
    7. Continuous Integration
    8. Deriving Team Standards for TDD
    9. Keeping Up with the Community
    10. Teardown
  18. Appendix 1: Comparing Unit Testing Tools
    1. Setup
    2. TDD Unit Testing Tool Features
    3. Notes on Google Mock
    4. Notes on CppUTest
    5. Other Unit Testing Frameworks
    6. Teardown
  19. Appendix 2: Code Kata: Roman Numeral Converter
    1. Setup
    2. Let’s Go!
    3. Practice Makes Perfect
    4. Teardown
  20. Appendix 3: Bibliography
    1. You May Be Interested In…