- Paperback: 296 pages
- Publisher: Manning Publications; 2 edition (December 7, 2013)
- Language: English
- ISBN-10: 1617290890
- ISBN-13: 978-1617290893
- Product Dimensions: 7.4 x 0.7 x 9.2 inches
- Shipping Weight: 1.1 pounds (View shipping rates and policies)
- Average Customer Review: 4.4 out of 5 stars See all reviews (26 customer reviews)
- Amazon Best Sellers Rank: #43,901 in Books (See Top 100 in Books)
Enter your mobile number or email address below and we'll send you a link to download the free Kindle App. Then you can start reading Kindle books on your smartphone, tablet, or computer - no Kindle device required.
To get the free app, enter your mobile phone number.
The Art of Unit Testing: with examples in C# 2nd Edition
Use the Amazon App to scan ISBNs and compare prices.
Prepare for your professional certification with study guides and exam prep tools from Wiley. See more
Frequently bought together
Customers who bought this item also bought
About the Author
Roy Osherove consults and trains teams worldwide on the gentle art of unit testing and test-driven development, and trains team leaders how to lead better at 5whys.com. He tweets at @RoyOsherove and has many videos about unit testing at ArtOfUnitTesting.com. His testing blog is at http://osherove.com/blog.
If you are a seller for this product, would you like to suggest updates through seller support?
Top Customer Reviews
The book is called "The ART of Unit Testing" for a reason. Roy Osherove is just as concerned (if not more concerned) with explaining how to write quality tests as he is with how to write a functioning test and for good reason - there's no point in writing tests that no one will want to run or understand later!
Don't look to this book for a comprehensive API on testing or mocking frameworks, but this book WILL give you the tools you need to understand what a unit test is, what an integration test is, what mocks and stubs are and the differences between them and it will give you enough high level information about many of the most popular testing and mocking frameworks for you to be up and writing tests very quickly.
Yes, examples are in C#, but the art of writing good tests goes beyond the language you use. The C# example code is highly readable, and even the usage of specific .NET mocking frameworks is acceptable since it stays light on the more language-specific details (e.g. parameterized tests, InternalsVisibleTo).
Here's what I found most useful:
* The definition of what a unit test is actually testing (a unit of work, i.e. the sum of actions from a public method call that produces a single noticeable end result)
* How to verify that single noticeable end result, and why certain types of verification (return values, public state/behavior change) are preferable to others (testing for interaction between objects)
* Using stubs to decouple your code from external dependencies
* Refactoring your code to create seams, inject new behavior, and ultimately make your code more testable and change-proof
* When it's appropriate to perform interaction testing with mocks
* The dangers of overspecifying tests - testing internal implementation vs. external behavior
* Detecting when your test is telling you that your production code sucks
* Smart ways to test event-related code
I enjoyed the author's balanced perspective on testing. He clearly lays out the pros and cons of each technique. This is important because it serves as a fair reminder that fancy design patterns and clever ways to mock and stub your code can hurt the readability and maintainability of your tests. Even when the author expresses an opinion, he makes it clear that it's only his opinion and not gospel.
For the most part, there isn't that much coverage of TDD. There's some discussion about red-green-refactor, and why it's good to see a test fail before it passes (answer: it tests your test). He makes a good point early on about why he won't cover that much about TDD: it requires that you know how to write good tests first, and to do that, you have to first see the code that needs testing.
Anyway, if you've ever sat down to write a unit test and got stuck asking yourself "what am I really testing here," this is the book for you.
At about 250 pages, this book is short enough to grasp the basic concepts and start writing unit tests in a weekend (that's how I approached it).
Some of the things that I really liked included:
* Selecting proper unit test and isolation frameworks.
* Common unit testing patterns.
* Learning the differences between fakes, stubs, and mocks (finally).
* In depth-coverage of the qualities that make for good unit tests--Chapter 8 is fantastic.
* The three main types of results that unit tests can assert against, and how unit tests differ from other types of testing (like integration testing).
* Understanding the need to design for testability, and some of the caveats when working with legacy or test-remiss code.
A lot of the book could apply to non-.NET developers, especially the second half of the book. However, I did find that as a C#/.NET developer, all of the information concerning tools was also relevant.
There are a few things that I felt could be improved with the book:
* The source code files could have been more organized.
* The code samples from chapters 3, 4, and 5 could have been more complete, for those of us who like to follow along.
* A larger or more complex example tying together the different unit testing techniques.
This book has helped me to improve the quality of my tests, and also the quality of the code I write. Highly recommended.