Thông tin tài liệu
www.it-ebooks.info
Test Driven
www.it-ebooks.info
www.it-ebooks.info
Test Driven
PRACTICAL TDD AND ACCEPTANCE TDD
FOR JAVA DEVELOPERS
LASSE KOSKELA
MANNING
Greenwich
(74° w. long.)
www.it-ebooks.info
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.
Sound View Court 3B fax: (609) 877-8256
Greenwich, CT 06830 email: orders@manning.com
©2008 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.
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.
Manning Publications Co. Copyeditor: Laura Merrill
Sound View Court 3B Typesetter: Gordan Salinovic
Greenwich, CT 06830 Cover designer: Leslie Haimes
ISBN 1-932394-85-0
Printed in the United States of America
12345678910–MAL –13121110090807
www.it-ebooks.info
To my colleagues,
for bugging me to finish this project.
And to my love Lotta,
who gave me the energy to do it.
www.it-ebooks.info
www.it-ebooks.info
vii
brief contents
PART 1 A TDD PRIMER 1
1 ■ The big picture 3
2
■ Beginning TDD 43
3
■ Refactoring in small steps 75
4
■ Concepts and patterns for TDD 99
PART 2APPLYING TDD
TO SPECIFIC TECHNOLOGIES 151
5 ■ Test-driving web components 153
6
■ Test-driving data access 195
7
■ Test-driving the unpredictable 249
8
■ Test-driving Swing 279
www.it-ebooks.info
viii BRIEF CONTENTS
PART 3BUILDING PRODUCTS
WITH ACCEPTANCE TDD 321
9 ■ Acceptance TDD explained 323
10
■ Creating acceptance tests with Fit 364
11
■ Strategies for implementing acceptance tests 396
12
■ Adopting TDD 435
appendix A
■ Brief JUnit 4 tutorial 467
a p p e n d i x B
■ Brief JUnit 3.8 tutorial 470
appendix C
■ Brief EasyMock tutorial 473
a p p e n d i x D
■ Running tests with Ant 475
www.it-ebooks.info
ix
contents
preface xvii
acknowledgments xix
about this book xxi
about the cover illustration xxvii
PART 1 A TDD PRIMER 1
1
The big picture 3
1.1 The challenge: solving the right problem right 5
Creating poorly written code 5
■
Failing to meet
actual needs 6
1.2 Solution: being test-driven 7
High quality with TDD 8
■
Meeting needs with
acceptance TDD 10
■
What’s in it for me? 11
1.3 Build it right: TDD 14
Test-code-refactor: the heartbeat 15
■
Developing
in small increments 19
■
Keeping code healthy with
refactoring 24
■
Making sure the software
still works 28
www.it-ebooks.info
[...]... 327 Example tests for a story 327 Properties of acceptance tests 328 Implementing acceptance tests 333 ■ ■ 9.3 Understanding the process The acceptance TDD cycle an iteration 343 9.4 334 334 ■ Acceptance TDD inside Acceptance TDD as a team activity 348 Defining the customer role 348 Who writes tests with the customer? 350 How many testers do we need? 350 ■ ■ 9.5 Benefits of acceptance TDD 351 Definition... Implementation strategies 104 Prime guidelines for test- driving ■ 106 ■ 4.2 Essential testing concepts 108 Fixtures are the context for tests 108 Test doubles stand in for dependencies 110 State and interaction-based testing 110 ■ ■ 4.3 Closer look into test doubles 113 Example of a test double 113 Stubs, fakes, and mocks 115 Mock objects in action 116 ■ ■ 4.4 Guidelines for testable designs 118 Choose composition... topics test- driven development and acceptance testdriven development—starting with the very basics Chapter 1 begins with a problem statement—the challenges we need to overcome and explains how TDD and acceptance TDD provide an effective solution in the form of test- first programming, evolutionary design, test automation, and merciless refactoring Chapter 2 gets our hands dirty, extending our understanding... the same page about what we’d like to accomplish and what’s standing in our way, we’ll create a roadmap for exploring how TDD and acceptance TDD can help resolve those problems, and 1 The acronym TDD is sometimes expanded to Test- Driven Design Another commonly used term for what we refer to as TDD is Test- First Programming They’re just different names for the same thing www.it-ebooks.info The challenge:... process with an extension to the core idea of TDD with what we call acceptance test- driven development (acceptance TDD or ATDD) We will drive development on the feature level by writing functional or acceptance tests for a feature before implementing the feature with TDD As a way of applying tests for more than just verification of the correctness of software, TDD is not exactly a new invention Many old-timers... the right thing: acceptance TDD What’s in a name? 31 a shared language 33 1.5 ■ 31 Close collaboration Tools for test- driven development 32 ■ Tests as 36 Unit-testing with xUnit 36 Test frameworks for acceptance TDD 37 Continuous integration and builds 37 Code coverage 39 ■ ■ 1.6 2 Summary ■ 41 Beginning TDD 43 2.1 From requirements to tests 45 Decomposing requirements 45 What are good tests made of?... should test for when test- driving UI code Then, we look at three design patterns that make our test- driven lives easier, and we briefly introduce two open source tools—Jemmy and Abbot for unit-testing Swing components We finish chapter 8 (and part 2) with an extended example, test- driving the face and behavior for a custom Swing component Part 3 is a change of tempo We move from the concrete world of test- driving... objects and classes into the fuzzier world of building whole systems in a test- first manner with acceptance TDD Chapter 9 gets us going with an introduction to user stories for managing requirements, and to the essence of acceptance tests Once we’re up to speed with the what, we focus on the how—the process of acceptance TDD and what it requires from the team We also crystallize the benefits of and the... strategies in our toolkit, from selecting tests to making them pass We also talk about essential testing concepts such as fixtures, test doubles, and the differences between state- and interaction-based testing After giving some guidelines for creating testable designs, chapter 4 ends with an overview of a number of key test patterns and a section on working in a test- first manner with legacy code Part... tests from the command line and as part of an Apache Ant build Chapter 11 expands our perspective by looking at a number of strategies for implementing our acceptance tests independent of the tools in use After going through our options for connecting tests to the system we’re developing, we discuss the kinds of limitations and opportunities that technology puts in our way We also share some tips for . www.it-ebooks.info
Test Driven
www.it-ebooks.info
www.it-ebooks.info
Test Driven
PRACTICAL TDD AND ACCEPTANCE TDD
FOR JAVA DEVELOPERS
LASSE KOSKELA
MANNING
Greenwich
(74°. WITH ACCEPTANCE TDD 321
9 ■ Acceptance TDD explained 323
10
■ Creating acceptance tests with Fit 364
11
■ Strategies for implementing acceptance tests
Ngày đăng: 17/03/2014, 12:20
Xem thêm: Test Driven: TDD and Acceptance TDD for Java Developers pptx, Test Driven: TDD and Acceptance TDD for Java Developers pptx, 1 The challenge: solving the right problem right, 4 Let’s not forget to refactor, apendix B: Brief JUnit 3.8 tutorial, D.2 The basics: compiling all source code