xUnit Test Patterns: Refactoring Test Code and over 670,000 other books are available for Amazon Kindle – Amazon’s new wireless reading device. Learn more

Buy New
 

or
Sign in to turn on 1-Click ordering.
Buy Used
Used - Good See details
$33.99 & this item ships for FREE with Super Saver Shipping. Details

or
Sign in to turn on 1-Click ordering.
 
   
Kindle Edition
 
   
Express Checkout with PayPhrase
What's this? | Create PayPhrase
More Buying Choices
Have one to sell? Sell yours here
or
Get a $30.57 Amazon.com Gift Card
xUnit Test Patterns: Refactoring Test Code
 
 
Start reading xUnit Test Patterns: Refactoring Test Code on your Kindle in under a minute.

Don’t have a Kindle? Get your Kindle here, or download a FREE Kindle Reading App.

xUnit Test Patterns: Refactoring Test Code [Hardcover]

Gerard Meszaros (Author)
4.7 out of 5 stars  See all reviews (16 customer reviews)

List Price: $64.99
Price: $47.99 & this item ships for FREE with Super Saver Shipping. Details
You Save: $17.00 (26%)
o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o
In Stock.
Ships from and sold by Amazon.com. Gift-wrap available.
Want it delivered Friday, September 10? Choose One-Day Shipping at checkout. Details
28 new from $39.95 20 used from $30.74
Textbook StudentJoin Amazon Student and get FREE Two-Day Shipping for one year with Amazon Prime shipping benefits.

Formats

Amazon Price New from Used from
Kindle Edition $38.39  
Hardcover $47.99  
Sell This Book Back for $30.57
Whether you buy it used on Amazon for $30.74 or somewhere else, you can sell it back to our Textbook Buyback Store at the current price of $30.57 through December 31, 2010. Restrictions Apply
Used Price$30.74
Buyback Price$30.57
Price after
Buyback
$0.17

Frequently Bought Together

xUnit Test Patterns: Refactoring Test Code + Test Driven Development: By Example + Working Effectively with Legacy Code
Price For All Three: $137.98

Show availability and shipping details

Buy the selected items together
  • In Stock.
    Ships from and sold by Amazon.com.
    This item ships for FREE with Super Saver Shipping. Details

  • Test Driven Development: By Example$40.64

    In Stock.
    Ships from and sold by Amazon.com.
    This item ships for FREE with Super Saver Shipping. Details

  • Working Effectively with Legacy Code$49.35

    In Stock.
    Ships from and sold by Amazon.com.
    This item ships for FREE with Super Saver Shipping. Details


Customers Who Bought This Item Also Bought


Editorial Reviews

Product Description

Automated testing is a cornerstone of agile development. An effective testing strategy will deliver new functionality more aggressively, accelerate user feedback, and improve quality. However, for many developers, creating effective automated tests is a unique and unfamiliar challenge.

xUnit Test Patterns is the definitive guide to writing automated tests using xUnit, the most popular unit testing framework in use today. Agile coach and test automation expert Gerard Meszaros describes 68 proven patterns for making tests easier to write, understand, and maintain. He then shows you how to make them more robust and repeatable--and far more cost-effective.

Loaded with information, this book feels like three books in one. The first part is a detailed tutorial on test automation that covers everything from test strategy to in-depth test coding. The second part, a catalog of 18 frequently encountered "test smells," provides trouble-shooting guidelines to help you determine the root cause of problems and the most applicable patterns. The third part contains detailed descriptions of each pattern, including refactoring instructions illustrated by extensive code samples in multiple programming languages.

Topics covered include

  • Writing better tests--and writing them faster
  • The four phases of automated tests: fixture setup, exercising the system under test, result verification, and fixture teardown
  • Improving test coverage by isolating software from its environment using Test Stubs and Mock Objects
  • Designing software for greater testability
  • Using test "smells" (including code smells, behavior smells, and project smells) to spot problems and know when and how to eliminate them
  • Refactoring tests for greater simplicity, robustness, and execution speed

This book will benefit developers, managers, and testers working with any agile or conventional development process, whether doing test-driven development or writing the tests last. While the patterns and smells are especially applicable to all members of the xUnit family, they also apply to next-generation behavior-driven development frameworks such as RSpec and JBehave and to other kinds of test automation tools, including recorded test tools and data-driven test tools such as Fit and FitNesse.


Visual Summary of the Pattern Language 
Foreword

Preface

Acknowledgments

Introduction

Refactoring a Test

PART I: The Narratives
Chapter 1 A Brief Tour
Chapter 2 Test Smells
Chapter 3 Goals of Test Automation
Chapter 4 Philosophy of Test Automation
Chapter 5 Principles of Test Automation
Chapter 6 Test Automation Strategy
Chapter 7 xUnit Basics
Chapter 8 Transient Fixture Management
Chapter 9 Persistent Fixture Management
Chapter 10 Result Verification
Chapter 11 Using Test Doubles
Chapter 12 Organizing Our Tests
Chapter 13 Testing with Databases
Chapter 14 A Roadmap to Effective Test Automation
PART II: The Test Smells 
Chapter 15 Code Smells
Chapter 16 Behavior Smells
Chapter 17 Project Smells
PART III: The Patterns 
Chapter 18 Test Strategy Patterns
Chapter 19 xUnit Basics Patterns
Chapter 20 Fixture Setup Patterns
Chapter 21 Result Verification Patterns
Chapter 22 Fixture Teardown Patterns
Chapter 23 Test Double Patterns
Chapter 24 Test Organization Patterns
Chapter 25 Database Patterns
Chapter 26 Design-for-Testability Patterns
Chapter 27 Value Patterns
PART IV: Appendixes
Appendix A Test Refactorings  
Appendix B xUnit Terminology 
Appendix C xUnit Family Members
Appendix D Tools
Appendix E Goals and Principles
Appendix F Smells, Aliases, and Causes
Appendix G Patterns, Aliases, and Variations
Glossary
References 

Index 


From the Back Cover

Automated testing is a cornerstone of agile development. An effective testing strategy will deliver new functionality more aggressively, accelerate user feedback, and improve quality. However, for many developers, creating effective automated tests is a unique and unfamiliar challenge.

xUnit Test Patterns is the definitive guide to writing automated tests using xUnit, the most popular unit testing framework in use today. Agile coach and test automation expert Gerard Meszaros describes 68 proven patterns for making tests easier to write, understand, and maintain. He then shows you how to make them more robust and repeatable--and far more cost-effective.

Loaded with information, this book feels like three books in one. The first part is a detailed tutorial on test automation that covers everything from test strategy to in-depth test coding. The second part, a catalog of 18 frequently encountered "test smells," provides trouble-shooting guidelines to help you determine the root cause of problems and the most applicable patterns. The third part contains detailed descriptions of each pattern, including refactoring instructions illustrated by extensive code samples in multiple programming languages.

Topics covered include

  • Writing better tests--and writing them faster
  • The four phases of automated tests: fixture setup, exercising the system under test, result verification, and fixture teardown
  • Improving test coverage by isolating software from its environment using Test Stubs and Mock Objects
  • Designing software for greater testability
  • Using test "smells" (including code smells, behavior smells, and project smells) to spot problems and know when and how to eliminate them
  • Refactoring tests for greater simplicity, robustness, and execution speed

This book will benefit developers, managers, and testers working with any agile or conventional development process, whether doing test-driven development or writing the tests last. While the patterns and smells are especially applicable to all members of the xUnit family, they also apply to next-generation behavior-driven development frameworks such as RSpec and JBehave and to other kinds of test automation tools, including recorded test tools and data-driven test tools such as Fit and FitNesse.


Visual Summary of the Pattern Language 
Foreword

Preface

Acknowledgments

Introduction

Refactoring a Test

PART I: The Narratives
Chapter 1 A Brief Tour
Chapter 2 Test Smells
Chapter 3 Goals of Test Automation
Chapter 4 Philosophy of Test Automation
Chapter 5 Principles of Test Automation
Chapter 6 Test Automation Strategy
Chapter 7 xUnit Basics
Chapter 8 Transient Fixture Management
Chapter 9 Persistent Fixture Management
Chapter 10 Result Verification
Chapter 11 Using Test Doubles
Chapter 12 Organizing Our Tests
Chapter 13 Testing with Databases
Chapter 14 A Roadmap to Effective Test Automation
PART II: The Test Smells 
Chapter 15 Code Smells
Chapter 16 Behavior Smells
Chapter 17 Project Smells
PART III: The Patterns 
Chapter 18 Test Strategy Patterns
Chapter 19 xUnit Basics Patterns
Chapter 20 Fixture Setup Patterns
Chapter 21 Result Verification Patterns
Chapter 22 Fixture Teardown Patterns
Chapter 23 Test Double Patterns
Chapter 24 Test Organization Patterns
Chapter 25 Database Patterns
Chapter 26 Design-for-Testability Patterns
Chapter 27 Value Patterns
PART IV: Appendixes
Appendix A Test Refactorings  
Appendix B xUnit Terminology 
Appendix C xUnit Family Members
Appendix D Tools
Appendix E Goals and Principles
Appendix F Smells, Aliases, and Causes
Appendix G Patterns, Aliases, and Variations
Glossary
References 

Index 



Product Details

  • Hardcover: 833 pages
  • Publisher: Addison-Wesley (May 31, 2007)
  • Language: English
  • ISBN-10: 0131495054
  • ISBN-13: 978-0131495050
  • Product Dimensions: 9.3 x 7.2 x 1.9 inches
  • Shipping Weight: 3.3 pounds (View shipping rates and policies)
  • Average Customer Review: 4.7 out of 5 stars  See all reviews (16 customer reviews)
  • Amazon Bestsellers Rank: #243,415 in Books (See Top 100 in Books)
    #62 in  Books > Computers & Internet > Programming > Software Design, Testing & Engineering > Testing

More About the Author

Gerard Meszaros
Discover books, learn about writers, read author blogs, and more.

Visit Amazon's Gerard Meszaros Page

Inside This Book (learn more)

What Do Customers Ultimately Buy After Viewing This Item?

xUnit Test Patterns: Refactoring Test Code
63% buy the item featured on this page:
xUnit Test Patterns: Refactoring Test Code 4.7 out of 5 stars (16)
$47.99
The Art of Unit Testing: With Examples in .Net
16% buy
The Art of Unit Testing: With Examples in .Net 4.7 out of 5 stars (25)
$26.39
Growing Object-Oriented Software, Guided by Tests
8% buy
Growing Object-Oriented Software, Guided by Tests 4.8 out of 5 stars (13)
$34.05
Test Driven Development: By Example
7% buy
Test Driven Development: By Example 3.9 out of 5 stars (34)
$40.64

Tags Customers Associate with This Product

 (What's this?)
Click on a tag to find related items, discussions, and people.
 
(17)
(15)

Your tags: Add your first tag
 

 

Customer Reviews

16 Reviews
5 star:
 (11)
4 star:
 (5)
3 star:    (0)
2 star:    (0)
1 star:    (0)
 
 
 
 
 
Average Customer Review
4.7 out of 5 stars (16 customer reviews)
 
 
 
 
Share your thoughts with other customers:
Most Helpful Customer Reviews

 
25 of 25 people found the following review helpful:
4.0 out of 5 stars All the important unit testing patterns and principles, but over-long, August 4, 2007
This review is from: xUnit Test Patterns: Refactoring Test Code (Hardcover)
Let me start by stating the obvious: this is a patterns book about the organisation of tests and the workings of the xUnit family of unit testing frameworks. It is _not_ a book about Test Driven Development, although there is material that is pertinent to that. Given that the use of JUnit and TDD is pretty intertwined in the minds of many Java developers, it's worth making this distinction, so you know what sort of book you're getting. Speaking of JUnit, most of the code examples uses Java, although there are some examples in C#, VB and Ruby.

Like Martin Fowler's Patterns of Enterprise Application Architecture, the book is split into two main sections, a narrative that weaves together a lot of the patterns and strategies, and then a catalogue of individual patterns. Between the two, there is a catalogue of 'test smells', similar to the 'code smells' discussed by Fowler in Refactoring, which I would suggest can be read profitably with the narrative section, rather than used as reference material.

There are a lot of patterns here on the mechanics of xUnit, such as 'Test Runner', 'Garbage-Collected Teardown' and 'Named Test Suite'. I was a bit confused about who this material is aimed at -- maybe someone looking at porting xUnit to a new programming language would find it useful, but a lot of it is fairly obvious to anyone who's used an xUnit in a non-trivial fashion (and certainly, if you haven't done so, this book is not a format that makes for a good introduction), or requires playing against xUnit's strengths (e.g. not putting setup and teardown code in their eponymous methods), although there is good reason for doing so in some of the examples provided, such as databases.

Beyond this, there is some good stuff on design-for-testability patterns (e.g. dependency injection versus dependency lookup), value patterns to replace magic constants, custom assertions and custom creation and other utility methods to make the intent of tests more clear. This material, along with the test smells chapter, is where the real value of the book lies. It encourages the application of the same software engineering principles you would apply to your applications (encapsulation, intent-revealing names, Don't Repeat Yourself) as you would to your testing code, something that's surprisingly easy to overlook, at least in my experience.

Also, the material on 'Test Doubles' (mocks, stubs, dummies and their ilk) is extremely useful. It touches on designing with mocks only superficially, but it does provide a helpful taxonomy of what different classes of doubles do. Now, if only everyone would standardise on this nomenclature, it would make life a lot easier. I suggest we brandish this enormous book threateningly at anyone who refuses to toe the line, and that should do the trick.

Because, boy, this book is big (about 900 pages). To be honest, it's too big. I rarely complain about getting too much book for my money, but the likes of GoF, PoEAA and PoSA 1 manage to come in between 400-500ish pages, so there's no reason XTP couldn't. The advantage is that the patterns in the catalogue, which take up most of the space, stand alone, without requiring too much flicking backwards and forwards between patterns.

The disadvantage is that there is a lot of repetition, so unlike the three design patterns books I mentioned above, which I suspect most people read cover to cover (or maybe that was just me and I'm a complete freak), I would suggest only dipping into the catalogue as necessary. For instance, how much difference is there between the 'Testcase Class per Class', 'Testcase Class per Feature' and the 'Testcase Class per Fixture' patterns? Not a lot, as you might expect.

I definitely liked this book. I would have liked it even more if it came in at about half its size and I would have preferred more emphasis on test and assertion organisation than the mechanics of the xUnit framework, but maybe that would have been a different type of book to the one Gerard Meszaros intended. This is nonetheless a must buy for anyone who cares about unit testing.
Help other customers find the most helpful reviews  
Was this review helpful to you? Yes No


 
11 of 11 people found the following review helpful:
5.0 out of 5 stars Seminal Work in Test-Driven Development, June 16, 2007
This review is from: xUnit Test Patterns: Refactoring Test Code (Hardcover)
We went over 2,000 unit tests this past week during Iteration 72 on our Agile project. Of course, over the course of the last 18-24 months we have removed some tests, and in many cases, refactored the existing tests many times. We also have been learning a whole lot about TDD and the actual domain that we are building and testing. As we were doing this, we were implicitly discovering Test Smells, and discovering test automation patterns. The value in establishing patterns, and more precisely a pattern language in a particular domain are substantial. It's not so much that the "collector" of patterns is defining something new (some often mistakenly criticize pattern books in that regard) that you didn't know, but defining a shared terminology of our practices that we keep doing over and over. To that end, the patterns themselves not only define a shared vocabulary but serve other functions, not the least of which is learning from others. An obvious example of this is Martin's PEAA collection of patterns that enables us to say things like PageController or Lazy Load or TableDataGateway and we all know what it means. In fact, when I am talking about Interaction versus State/Behavior type of testing on CB, and others here use much of this terminology, I am in fact, talking about patterns like TestDoubles and MockObjects, among others.

When I became aware that Gerard Meszaros ' xUnit Test Patterns book was going to ship Friday, I ordered it for overnight delivery on Saturday. I read well over 200 pages yesterday pretty much at one sitting, contented with a book that will change the face of the software industry, just as JUnit and all the other xUnit family have fundamentally altered software development for the better. Its definitely a big book at 944 pages, but it's not a book of excess, unnecessary pages. Rather it shows how hard it is to write defect-free software and the depth of the work that people are putting into this endeavor. The book uses Java as the language which obviously is no hardship to the C# programmer. Like most of the sound practices that have been evolving in the last ten years, this work has been evolving out of the terrific Java community.

Just like their are Code Smells, there are Test Smells, and writing good test code is just as hard and as worthy as writing good production code. Meszaros categorizes Test Smells into ProjectSmells, BehaviorSmells, and CodeSmells. Particularly interesting is his discussion in this regard to the commercial "record and playback" test automation products that have given test automation a bad name in many circles with their tendency to create FragileTests particularly with regard to Interface Sensitivity. Like many others, we were drawn in, and spent and wasted thousands of dollars with a vendor and exhibiting extreme Interface Sensitivity with the user interface. Their interface was not only unable to "pick up" most of the controls we use but even minor changes to the interface can cause tests to fail, even in circumstances in which a human user would say the test should pass. This only goes to support the notion many of us have talked about here about factoring a UI into MVP or MVC and not having logic in the "presentation."

Meszaros goes onto to provide very valuable discussions of Goals of Test Automation, Philosophies of Test Automation, and a Roadmap to Test Automation. We talk about things like Tests as Specification, also known as Executable Specification: "If we are doing test-driven development or test-first development, the tests give us a way to capture what the SUT should be doing before we start implementing it. They give us a way to specify the behavior in various scenarios captured in a form that we can then execute (essentially an "executable specification".) To ensure we are "building the right software", we must ensure that our tests reflect how the SUT will actually be used." We also talk about Tests as Documentation.

The main part of the book, of course, is the catalog of the patterns. Meszaros has provided a tremendous service to our community by not only cataloging and naming much of what we do, but also providing excellent discussions of why and how we do those things. I think, over time, this will be regarded as a seminal work in Software Development.
Help other customers find the most helpful reviews  
Was this review helpful to you? Yes No


 
13 of 14 people found the following review helpful:
5.0 out of 5 stars Fills an important void, June 6, 2007
This review is from: xUnit Test Patterns: Refactoring Test Code (Hardcover)
Writing good tests is not easy. Different developers have come up with many techniques to improve tests. You might have used Backdoor Manipulation to make tests faster or used Custom Assertions to make an Obscure Test more readable. Sometimes a failing test caused you to play Assertion Roulette while you were trying to figure out who the Mystery Guest in this test is and what role he plays.

Gerard documented these (and many more) smells and patterns to help you write better tests. If you have written tests, you have probably used some of them, but even then looking at the patterns described in this book will help you tune your technique. For example Custom Assertions should always take the actual and expected values as parameters, so assertMagicObjectsAreEqual(actual, expected) is good, assertEverythingIsAlright(actual) is bad. And now you have a name for this technique, which makes it easier to explain to your fellow developers what you are doing. At 800+ pages you are bound to find plenty of new techniques as well.

If you are worried that this is another work by the pattern weenies, rest assured. The book follows the very simple and pragmatic "How It Works" and "When to Use It" format also used by Martin Fowlers' Patterns of Enterprise Application Architecture.
Help other customers find the most helpful reviews  
Was this review helpful to you? Yes No

Share your thoughts with other customers: Create your own review
 
 
 
Most Recent Customer Reviews

5.0 out of 5 stars Authoritative and extremely useful
I think the title is a bit misleading, because this book is about a lot more than just writing good test code. Read more
Published 1 month ago by Jas Bro

5.0 out of 5 stars Principles and Concepts for Pragmatic Test Management
If TDD or its kin survive, it will be largely due to adoption of manageable tactics for testing. This book is unprecedented in supplying principles and conceptual tools hopefully... Read more
Published 4 months ago by Gary

5.0 out of 5 stars Awesome book must have for any software developer
Our team has been doing TDD for 6 years since the seminal Kent Beck book.
We as a team have learnt read and improved our practice over these years but this book has had the... Read more
Published 9 months ago by A. B. Powell

4.0 out of 5 stars Found it
It's what I was looking for. It is giving me a good reference and compass to TDD.
Published 10 months ago by Tech Book Addict

5.0 out of 5 stars Good Desk Reference
Good book, I keep it on my desk at work. There is a pretty substantial website with nearly the same information online, however even after reading most of that site, I still... Read more
Published 12 months ago by Tara Nicholson

4.0 out of 5 stars More xUnit patterns than you would wish!

xUnit Test Patterns by Gerard Meszaros is a huge book. It is almost 900 pages of patterns to be used for test automation and for unit testing. Read more
Published 14 months ago by Bas Vodde

5.0 out of 5 stars Much needed addition for those using TDD
x/Unit patterns is a great book that fills a void I unconsciously would run into in projects using TDD. Read more
Published 16 months ago by Matthew Penner

4.0 out of 5 stars Very valuable information communicated multiple times
I agree with the other reviewers who say that this book contains lots of valuable information. It covers the subject completely, and effectively. Read more
Published 16 months ago by David S Bakin

5.0 out of 5 stars The "Design Patterns" of Automated Testing
I'm writing this review quite some time after the book was published, but I get a sense that there are people out there who haven't read or even heard of this book but who... Read more
Published 17 months ago by Alexei Zheglov

5.0 out of 5 stars Inspired to Test
I've been familiar with agile concepts of automated unit testing (AUT) and test-driven development (TDD) for awhile now. Read more
Published on December 23, 2007 by C. Kilgore

Only search this product's reviews



Customer Discussions

This product's forum
Discussion Replies Latest Post
This book has a web site 0 October 2006
See all discussions...  
Start a new discussion
Topic:
First post:
Prompts for sign-in
 


Active discussions in related forums
Search Customer Discussions
   



So You'd Like to...



Look for Similar Items by Category


Look for Similar Items by Subject

 

Feedback

If you need help or have a question for Customer Service, contact us.
 Would you like to update product info or give feedback on images?
Is there any other feedback you would like to provide?

Your comments can help make our site better for everyone.


Your Recent History

 (What's this?)

After viewing product detail pages or search results, look here to find an easy way to navigate back to pages you are interested in.