the art of with examples in C# SECOND EDITION FOREWORDS BY Michael Feathers Robert C. Martin R O M A N N I N G OY SHEROVE The Art of Unit Testing, Second Edition Download from Wow! eBook <www.wowebook.com> Download from Wow! eBook <www.wowebook.com> The Art of Unit Testing Second Edition WITH EXAMPLES IN C# ROY OSHEROVE MANNING SHELTER ISLAND Download from Wow! eBook <www.wowebook.com> For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 261 Shelter Island, NY 11964 Email: [email protected] ©2014 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Photographs in this book were created by Martin Evans and Jordan Hochenbaum, unless otherwise noted. Illustrations were created by Martin Evans, Joshua Noble, and Jordan Hochenbaum. Fritzing (fritzing.org) was used to create some of the circuit diagrams. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. Manning Publications Co. Development editor: Nermina Miller 20 Baldwin Road Copyeditor: Linda Recktenwald PO Box 261 Proofreader: Elizabeth Martin Shelter Island, NY 11964 Typesetter: Dennis Dalinnik Cover designer: Marija Tudor ISBN: 9781617290893 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – EBM – 19 18 17 16 15 14 13 Download from Wow! eBook <www.wowebook.com> To Tal, Itamar, Aviv, and Ido. My family. Download from Wow! eBook <www.wowebook.com> Download from Wow! eBook <www.wowebook.com> brief contents PART 1 GETTING STARTED . .....................................................1 1 ■ The basics of unit testing 3 2 ■ A first unit test 19 PART 2 CORE TECHNIQUES ....................................................47 3 ■ Using stubs to break dependencies 49 4 ■ Interaction testing using mock objects 75 5 ■ Isolation (mocking) frameworks 90 6 ■ Digging deeper into isolation frameworks 109 PART 3 THE TEST CODE .......................................................123 7 ■ Test hierarchies and organization 125 8 ■ The pillars of good unit tests 151 PART 4 DESIGN AND PROCESS ...............................................187 9 ■ Integrating unit testing into the organization 189 10 ■ Working with legacy code 207 11 ■ Design and testability 219 vii Download from Wow! eBook <www.wowebook.com> Download from Wow! eBook <www.wowebook.com> contents foreword to the second edition xv foreword to the first edition xvii preface xix acknowledgments xxi about this book xxii about the cover illustration xxvi PART 1 GETTING STARTED . ..........................................1 1 The basics of unit testing 3 1.1 Defining unit testing, step by step 4 The importance of writing good unit tests 5 ■ We’ve all written unit tests (sort of) 5 1.2 Properties of a good unit test 6 1.3 Integration tests 7 Drawbacks of nonautomated integration tests compared to automated unit tests 9 1.4 What makes unit tests good 11 1.5 A simple unit test example 11 1.6 Test-driven development 14 ix Download from Wow! eBook <www.wowebook.com>
Description: