
- 292 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
About this book
Summary The Art of Unit Testing, Second Edition guides you step by step from writing your first simple tests to developing robust test sets that are maintainable, readable, and trustworthy. You'll master the foundational ideas and quickly move to high-value subjects like mocks, stubs, and isolation, including frameworks such as Moq, FakeItEasy, and Typemock Isolator. You'll explore test patterns and organization, working with legacy code, and even "untestable" code. Along the way, you'll learn about integration testing and techniques and tools for testing databases and other technologies. About this Book You know you should be unit testing, so why aren't you doing it? If you're new to unit testing, if you find unit testing tedious, or if you're just not getting enough payoff for the effort you put into it, keep reading. The Art of Unit Testing, Second Edition guides you step by step from writing your first simple unit tests to building complete test sets that are maintainable, readable, and trustworthy. You'll move quickly to more complicated subjects like mocks and stubs, while learning to use isolation (mocking) frameworks like Moq, FakeItEasy, and Typemock Isolator. You'll explore test patterns and organization, refactor code applications, and learn how to test "untestable" code. Along the way, you'll learn about integration testing and techniques for testing with databases.The examples in the book use C#, but will benefit anyone using a statically typed language such as Java or C++.Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications. What's Inside
- Create readable, maintainable, trustworthy tests
- Fakes, stubs, mock objects, and isolation (mocking) frameworks
- Simple dependency injection techniques
- Refactoring legacy code
About the Author Roy Osherove has been coding for over 15 years, and he consults and trains teams worldwide on the gentle art of unit testing and test-driven development. His blog is at ArtOfUnitTesting.com. Table of Contents
PART 1 GETTING STARTED
- The basics of unit testing
- A first unit test
- PART 2 CORE TECHNIQUES
- Using stubs to break dependencies
- Interaction testing using mock objects
- Isolation (mocking) frameworks
- Digging deeper into isolation frameworks
- PART 3 THE TEST CODE
- Test hierarchies and organization
- The pillars of good unit tests
- PART 4 DESIGN AND PROCESS
- Integrating unit testing into the organization
- Working with legacy code
- Design and testability
Frequently asked questions
- Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
- Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Information
Part 1. Getting started
Chapter 1. The basics of unit testing
- Defining a unit test
- Contrasting unit testing with integration testing
- Exploring a simple unit testing example
- Understanding test-driven development
1.1. Defining unit testing, step by step
Definition 1.0
Definition
- The invoked public method returns a value (a function thatâs not void).
- Thereâs a noticeable change to the state or behavior of the system before and after invocation that can be determined without interrogating private state. (Examples: the system can log in a previously nonexistent user, or the systemâs properties change if the system is a state machine.)
- Thereâs a callout to a third-party system over which the test has no control, and that third-party system doesnât return any value, or any return value from that system is ignored. (Example: calling a third-party logging system that was not written by you and you donât have the source to.)
Updated Definition 1.1
1.1.1. The importance of writing good unit tests
1.1.2. Weâve all written unit tests (sort of)
Figure 1.1. In classic testing, developers use a graphical user interface (GUI) to trigger an action on the class they want to test. Then they check the results.

Table of contents
- Copyright
- Brief Table of Contents
- Table of Contents
- Foreword to the Second Edition
- Foreword to the First Edition
- Preface
- Acknowledgments
- About this Book
- About the Cover Illustration
- Part 1. Getting started
- Part 2. Core techniques
- Part 3. The test code
- Part 4. Design and process
- Appendix. Tools and frameworks
- Index
- List of Figures
- List of Tables
- List of Listings