Unit Testing Principles, Practices, and Patterns

Book description

Unit Testing Principles, Patterns and Practices teaches you to design and write tests that target the domain model and other key areas of your code base. In this clearly written guide, you learn to develop professional-quality test suites, safely automate your testing process, and integrate testing throughout the application life cycle. As you adopt a testing mindset, you’ll be amazed at how better tests cause you to write better code.

Table of contents

  1. Copyright
  2. Brief Table of Contents
  3. Table of Contents
  4. Preface
  5. Acknowledgments
  6. About this book
  7. About the author
  8. About the cover illustration
  9. Part 1. The bigger picture
    1. Chapter 1. The goal of unit testing
      1. 1.1. The current state of unit testing
      2. 1.2. The goal of unit testing
      3. 1.3. Using coverage metrics to measure test suite quality
      4. 1.4. What makes a successful test suite?
      5. 1.5. What you will learn in this book
      6. Summary
    2. Chapter 2. What is a unit test?
      1. 2.1. The definition of “unit test”
      2. 2.2. The classical and London schools of unit testing
      3. 2.3. Contrasting the classical and London schools of unit testing
      4. 2.4. Integration tests in the two schools
      5. Summary
    3. Chapter 3. The anatomy of a unit test
      1. 3.1. How to structure a unit test
      2. 3.2. Exploring the xUnit testing framework
      3. 3.3. Reusing test fixtures between tests
      4. 3.4. Naming a unit test
      5. 3.5. Refactoring to parameterized tests
      6. 3.6. Using an assertion library to further improve test readability
      7. Summary
  10. Part 2. Making your tests work for you
    1. Chapter 4. The four pillars of a good unit test
      1. 4.1. Diving into the four pillars of a good unit test
      2. 4.2. The intrinsic connection between the first two attributes
      3. 4.3. The third and fourth pillars: Fast feedback and maintainability
      4. 4.4. In search of an ideal test
      5. 4.5. Exploring well-known test automation concepts
      6. Summary
    2. Chapter 5. Mocks and test fragility
      1. 5.1. Differentiating mocks from stubs
      2. 5.2. Observable behavior vs. implementation details
      3. 5.3. The relationship between mocks and test fragility
      4. 5.4. The classical vs. London schools of unit testing, revisited
      5. Summary
    3. Chapter 6. Styles of unit testing
      1. 6.1. The three styles of unit testing
      2. 6.2. Comparing the three styles of unit testing
      3. 6.3. Understanding functional architecture
      4. 6.4. Transitioning to functional architecture and output-based testing
      5. 6.5. Understanding the drawbacks of functional architecture
      6. Summary
    4. Chapter 7. Refactoring toward valuable unit tests
      1. 7.1. Identifying the code to refactor
      2. 7.2. Refactoring toward valuable unit tests
      3. 7.3. Analysis of optimal unit test coverage
      4. 7.4. Handling conditional logic in controllers
      5. 7.5. Conclusion
      6. Summary
  11. Part 3. Integration testing
    1. Chapter 8. Why integration testing?
      1. 8.1. What is an integration test?
      2. 8.2. Which out-of-process dependencies to test directly
      3. 8.3. Integration testing: An example
      4. 8.4. Using interfaces to abstract dependencies
      5. 8.5. Integration testing best practices
      6. 8.6. How to test logging functionality
      7. 8.7. Conclusion
      8. Summary
    2. Chapter 9. Mocking best practices
      1. 9.1. Maximizing mocks’ value
      2. 9.2. Mocking best practices
      3. Summary
    3. Chapter 10. Testing the database
      1. 10.1. Prerequisites for testing the database
      2. 10.2. Database transaction management
      3. 10.3. Test data life cycle
      4. 10.4. Reusing code in test sections
      5. 10.5. Common database testing questions
      6. 10.6. Conclusion
      7. Summary
  12. Part 4. Unit testing anti-patterns
    1. Chapter 11. Unit testing anti-patterns
      1. 11.1. Unit testing private methods
      2. 11.2. Exposing private state
      3. 11.3. Leaking domain knowledge to tests
      4. 11.4. Code pollution
      5. 11.5. Mocking concrete classes
      6. 11.6. Working with time
      7. 11.7. Conclusion
      8. Summary
  13. Chapter Map
  14. Index
  15. List of Figures
  16. List of Tables
  17. List of Listings

Product information

  • Title: Unit Testing Principles, Practices, and Patterns
  • Author(s): Vladimir Khorikov
  • Release date: January 2020
  • Publisher(s): Manning Publications
  • ISBN: 9781617296277