The Art Of Unit Testing, Second Edition
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
TL;DR In its new edition, the art of unit testing subtly changes the definition of good unit tests from testing units of code in isolation to testing units of work. Testing units of work will increase the maintainability of your unit tests tenfold. The book remains being an awesome introduction to unit testing and will help you write more readable, maintainable and trustworthy tests.
With the second edition of The Art of Unit Testing @royosherove makes a subtle change in his definition of a good unit test that makes a world of difference in terms of improving the maintainability of your tests. Instead of a good unit test being a test of a unit of code (method/class) in isolation, a good unit test is a test of a unit of work in isolation where this unit of work is:
The second edition was published in 2013. It has two additional chapters, as well as reorganization and updating of chapters from the first edition. The second edition is still in print and is available at the Manning Publications website.
SummaryThe 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 BookYou 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 AuthorRoy 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
As organizations shift from monolithic applications to smaller, self-contained microservices, distributed systems have become more fine-grained. But developing these new systems brings its own host of problems. This expanded second edition takes a holistic view of topics that you need to consider when building, managing, and scaling microservices architectures. Through clear examples and practical advice, author Sam Newman gives everyone from architects and developers to testers and IT operators a firm grounding in the concepts.
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 listening. The examples in the audiobook use C# but will benefit anyone using a statically typed language such as Java or C++.
Overall, I think this is a great book on unit testing. Roy is certainly well-qualified to write on this topic, and he does an excellent job of describing how to get started with unit testing, how to get the necessary tools, and how to write your first test. As the book proceeds, he goes into more detail on how to break dependencies and use mock objects, how to organize tests, and what separates good tests from bad.
Dave Farley: I was particularly intrigued by your take on separating unit testing from TDD because that's not a way that I've thought about it. Well, I've seen them as separate things but I haven't thought about the quality of the tests divorced from TDD. One of the things that I like about TDD is the way it gives me feedback on the quality of my design as the design evolves. But I did like your take, reading through the book, on the focus on the separate tests. So one of the things that I really enjoyed early on in the third edition of the book is the idea of the exit points.
Roy Osherove: So I think this is the part that to me these days other than, you know, writing a technical book, I think that the part that the most amazes me and intrigues me is how humans behave because I think that is essentially the biggest challenge that we have as leaders, as coaches, consultants, whatever it is we are, each one of us at each company wants to do the best thing but not only in their head, they want other people to also do the same thing. So influencing behavior has been one of the areas that I've cared about in the past few years. And I've learned a lot about it and I wrote about it in my book about elastic leadership. And I also plan to include parts of it in the third edition, and I've started to talk about it in the second edition as well.
A big thank you to Michael Stephens and Nermina Miller at Manning, who were patient with me every step of the long way it took to write this book. Thanks also to everyone else at Manning who worked on the second edition in production and behind the scenes.
Thank you Jim Newkirk, Michael Feathers, Gerard Meszaros, and many others, who provided me with inspiration and the ideas that made this book what it is. And a special thank you to Uncle Bob Martin for agreeing to write the foreword to the second edition.
In this second edition, I added material about constrained versus unconstrained isolation frameworks, and a new chapter 6 on what makes for a good isolation framework and how frameworks like Typemock work under the covers.
Part 1 takes you from zero to 60 in writing unit tests. Chapters 1 and 2 cover the basics, such as how to use a testing framework (NUnit), and introduce the basic automated test attributes, such as [Test] and [TestCase]. They also introduce the ideas of asserts, ignoring tests, unit-of-work testing, the three end result types of a unit test, and the three types of tests you need for them: value tests, state-based tests, and interaction tests.
The second part of the book chapters 3, 4 and 5, details the core techniques of how to use stub, what mocks are and using mocking framework Rhino Mocks to do unit testing. These three chapters I believe are quite important for a beginner to go through, since in chapter 3, the author goes through the techniques of Extract and Override, using Factories and Dependency Injection through constructor/properties. The author also talks about when should one use these techniques, the pros and cons of them.
Beginning the second quarter of 1999, a change was made in the way data for housing units in structure were collected. In the past, there was one category to show 1-unit in structure. That has been broken into two categories: 1-unit attached and 1-unit detached.
The HVS estimation procedure for vacant units is similar to that used for occupied units. Weighted sample results were adjusted at the state level using 2000 census vacant counts. A second adjustment inflated these results based on the CPS coverage of occupied units by geographic areas. As a final step for both the CPS and HVS, all housing unit counts were adjusted to reflect independent housing control totals. This change was effective, beginning in the first quarter 2003.
Data shown in all tables (except table 3) on vacancy rates and tenure of occupied units for the second quarter 2008 are from the CPS/HVS and are averaged for the three months, April, May, and June 2008. The data concerning the distribution of characteristics for occupied housing units, shown in table 3, were obtained primarily from the AHS national sample. Distributions of characteristics of occupied housing units from the AHS estimates were applied to CPS current housing inventory independent estimates to obtain the characteristics of occupied housing units used in this report. The Survey of Construction (SOC) and the Consumer Price Index also were used to improve estimates of the rent distribution. 041b061a72