The Art of Unit Testing: With Examples in .net (英語) ペーパーバック – 2009/6/28
Kindle 端末は必要ありません。無料 Kindle アプリのいずれかをダウンロードすると、スマートフォン、タブレットPCで Kindle 本をお読みいただけます。
HIGHLIGHTHereÂ s what Michael Feathers, an Agile rock star in his own right, has to sayabout The Art of Unit Testing : Â This is the best all around introduction to unittesting on the market today.Â DESCRIPTIONThe Art of Unit Testing guides the reader on the journey from beginner to masterin the subtle art of unit testing. Based on expert author Roy OsheroveÂ sreal-world development experiences, this book shows developers how to makesure the code that they write actually works as expected, and how to make theseverifications as automated as possible. Not only that, the book shows techniquesthat help to make sure that tests are maintainable, readable, and test the rightthing over time.The author establishes five rules for good unit tests built upon the three majorprinciples that any good test be maintainable, trustworthy, and readable. Clearsections present established best practices, and the book also provides clear guidanceon what to test and where to start testing in a legacy code project.Unlike other books on this topic, this book trades theory for real-world examples.ItÂ s designed so that a working developer can start writing better unit testsnow. Unlike most Unit Testing and TDD books, most examples are in C#on the .NET platform.KEY POINTSÂ Introduction to unit testing and the basics of writing real-world unit testsÂ Best practices for writing maintainable, trustworthy, readable testsÂ Author Roy Osherove is highly visible and extremely well-known in this fieldMARKET INFORMATIONAgile principles like unit testing have found their way more slowly into theMicrosoft community than they have in Java. This book presents the well-honedpractices common in the Java world using examples in C#.
For over a decade, Roy Osherove has been a developer, lead, manager, and architect.Roy speaks at international conferences such as TechEd, DevTeach, JAOO,and DevDays about subjects relating to Agile development, unit testing and testdrivendevelopment. HeÂ s the founder of the Agile Israel User group and consultsand trains teams around the world.
Chapter 1 #available online at [...] is a brief but helpful introduction to unit testing and TDD #Test Driven Development#. I'd recommend it for anyone who is new to these subjects.
Chapters 2-5 teach how to use test and mock frameworks. They are .NET specific in the sense that the author uses NUnit and Rhino Mocks, but the definitions and descriptions in those chapters are applicable to other frameworks as well. I haven't tried it, but I suspect that the code could be put in C++ classes and run under Google Mocks & Test without many changes.
Chapters 6-7 are the heart of this book. They teeach how to write good tests and how to organize them. If you're already doing TDD, you could skip the rest of the book and just read these two chapters. They're worth the price of admission.
The last two chapters discuss how to introduce TDD to an organization and how to deal with legacy code. Osherove is a consultant, so he has had plenty of experience with introducing TDD. His suggestion to bring in a consultant is a bit self-serving, but has some merit. The legacy code chapter is mostly an overview of Feathers' book, but a good one.
Roy Osherove has a lot of experience helping companies with "the art" of unit testing. He believes the key to successful unit testing rests on three pillars: maintainability, readability, and trustworthiness. He explains in the book what those things actually look like in real-world examples and why you might not be getting everything you could be out of your tests if you overlook one of those.
Roy also includes a fairly detailed comparison of the latest tools and frameworks you have to choose from. This section alone could save a ton of research time by getting a fairly unbiased, expert's view of the pros and cons for these types of tools and frameworks:
- Test Frameworks: NUnit, MSTest, MbUnit, Gallio, xUnit, Pex
- Isolation Frameworks: Moq, Rhino Mocks, Typemock Isolator, NMock, NUnit.Mocks
- IoC Containers: StructureMap, Unity, Castle Windsor, Autofac, Common Service Locator (CSL), Spring.NET, Managed Extensibility Framework (MEF), Ninject
- Web Testing: Ivonna, VS Team System Web Test, NUnitAsp, Watir, WatiN, Selenium
- UI Testing: NUnitForms, Project White, Team System UI Tests
- Thread-Related Testing: Typemock Racer, Microsoft CHESS
- Acceptance Testing: FitNesse, StoryTeller
This book was a short 320 pages, but there is a ton of practical and applicable tips jammed between the covers. But, I have to mention that this book isn't as polished as you would probably expect with most published works. It isn't anything major, but just a few things in the text or code samples that should have been caught by testers or an editor. These issues don't really take away from the content, but it just wasn't up to the standard I expect when buying a published work. (And that is possibly the worst cover I have ever seen ... yes, I get the reference to "The Art of War").
If you are remotely interested in this topic, you should listen to a recent podcast Roy did with Scott Hanselman on "The Art of Unit Testing." Although the podcast is kind of like a cliff-notes version of the book ... it isn't a replacement. If you find the podcast remotely helpful, order the book.
To read the full review or view more technical book reviews like this, visit [...].
I'd like to thank the author of this book for writing it.
I've been writing unit tests for quite some time now and this book contributed my knowledge tremendously.
Before this book, I had a lot of questions to ask about unit testing and most of them where "how?" questions.
How to write a good unit test ?
How to write tests in isolation and decouple the dependencies in complex scenarios ?
How to write fake objects properly and understand the differences between the various fake objects in Unit Testing.
How to write scalable and maintainable unit tests ?
The only thing I dislike and I think the author should reconsider is the remark about virtual methods "Make methods virtual by default" while this may be convenient it comes with serious implications and I think there's a lot more to write about it rather than suggesting developers that they should do so, even though he wrote an alternative, the title says it all.
However, this book definitely stands for its title!