effective unit testing

249 652 0
effective unit testing

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

MANNING A guide for Java developers L ASSE KOSKELA www.it-ebooks.info Effective Unit Testing www.it-ebooks.info www.it-ebooks.info Effective Unit Testing A GUIDE FOR JAVA DEVELOPERS LASSE KOSKELA MANNING SHELTER ISLAND 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. 20 Baldwin Road PO Box 261 Shelter Island, NY 11964 Email: orders@manning.com ©2013 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. 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: Frank Pohlman 20 Baldwin Road Copyeditor: Benjamin Berg PO Box 261 Technical proofreader: Phil Hanna Shelter Island, NY 11964 Proofreader: Elizabeth Martin Typesetter: Dottie Marsico Cover designer: Marija Tudor ISBN 9781935182573 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – MAL – 18 17 16 15 14 13 www.it-ebooks.info Few sights are as captivating as the pure joy of learning new things. www.it-ebooks.info www.it-ebooks.info vii brief contents PART 1 FOUNDATIONS 1 1 ■ The promise of good tests 3 2 ■ In search of good 15 3 ■ Test doubles 27 PART 2 CATALOG 45 4 ■ Readability 47 5 ■ Maintainability 78 6 ■ Trustworthiness 115 PART 3 DIVERSIONS . 137 7 ■ Testable design 139 8 ■ Writing tests in other JVM languages 156 9 ■ Speeding up test execution 170 www.it-ebooks.info www.it-ebooks.info ix contents preface xv acknowledgments xvii about this book xix about the cover illustration xxiv PART 1 FOUNDATIONS 1 1 The promise of good tests 3 1.1 State of the union: writing better tests 4 1.2 The value of having tests 5 Factors of productivity 8 ■ The curve of design potential 10 1.3 Tests as a design tool 10 Test-driven development 11 ■ Behavior-driven development 13 1.4 Summary 14 2 In search of good 15 2.1 Readable code is maintainable code 16 2.2 Structure helps make sense of things 18 2.3 It’s not good if it’s testing the wrong things 20 2.4 Independent tests run easily in solitude 21 www.it-ebooks.info [...]... JUnit’s popularity and status as the de facto unit test framework within the Java community, not all Java programmers are familiar with this great little open source library We’ve included two appendices to help those individuals and programmers who haven’t squeezed all the horsepower out of JUnit’s more advanced features Appendix A offers a brief introduction to writing tests with JUnit and how JUnit... experience levels who are looking to improve the quality of the unit tests they write While we do provide appendices that teach you about a test framework (JUnit), our primary goal is to help Java programmers who already know how to write unit tests with their test framework of choice to write better unit tests Regardless of how many unit tests you’ve written so far, we’re certain that you can still... you’re reading right now so head over to the Author Online forum for this book at www.manning.com/EffectiveUnitTesting There’s also an active community of test-infected programmers over at the testdrivendevelopment and extremeprogramming Yahoo! Groups While these forums aren’t exclusively for discussions about unit tests, they are excellent places for holding those discussions Besides, maybe you’ll manage... the spot Author Online Purchase of Effective Unit Testing includes free access to a private web forum run by Manning Publications, where you can make comments about the book, ask technical questions, and receive help from the author and from other users To access the forum and subscribe to it, point your web browser to http://www.manning.com/ EffectiveUnitTesting This page provides information on how... enable you to gain and sustain development speed Help! I’m new to unit testing If you aren’t that familiar with writing automated tests, this would be a good time to get acquainted with that practice Manning has released several books on JUnit, the de facto standard library for writing unit tests for Java, and the second edition of JUnit in Action (written by Petar Tahchiev, et al and published in... 196 ■ ■ 9.4 appendix A appendix B Summary 200 JUnit primer 202 Extending JUnit 209 index 217 www.it-ebooks.info www.it-ebooks.info preface On the night of June 10, 2009, I found an email in my inbox from Christina Rudloff from Manning, asking me if I knew anyone who might be a good candidate to write a Java edition of Roy Osherove’s book, The Art of Unit Testing in NET I told her I’d do it That was a... ourselves and developing our sense for unit tests That sense is as much about what good unit tests are like as it is about what not-sogood unit tests are like There may be some absolute truths involved (such as that a code comment repeating exactly what the code says is redundant and should be removed) but the vast majority of the collective body of knowledge about unit tests is highly context-sensitive... be more than capable of writing tests and making assertions with JUnit’s API Appendix B takes a deeper dive into the JUnit API with the goal of extending its built-in functionality While not trying to cover everything about JUnit to the last bit of detail, we’ve chosen to give you a brief overview of the two common ways of extending JUnit—rules and runners—and devote this appendix to showcasing some... developer testing, head over to the CodeRanch at http://www.coderanch.com and the excellent Testing forum Again, a lovely group of very helpful people over there Most importantly, however, I suggest that you actively talk about your test code with your peers at work Some of the best insights I’ve had about my code have been through having someone else look at it on the spot Author Online Purchase of Effective. .. using a monospaced font, to make them stand out Many longer listings have numbered annotations that we refer to in the text Code downloads The Manning website page for this book at www.manning.com/EffectiveUnitTesting offers a source code package you can download to your computer This includes selected parts of the source code shown in the book, should you want to take things further from where we left . guide for Java developers L ASSE KOSKELA www.it-ebooks.info Effective Unit Testing www.it-ebooks.info www.it-ebooks.info Effective Unit Testing A GUIDE FOR JAVA DEVELOPERS LASSE KOSKELA MANNING SHELTER. teaching our- selves and developing our sense for unit tests. That sense is as much about what good unit tests are like as it is about what not-so- good unit tests are like. There may be some absolute. higher-powered CPU 194 ■ Distribute the build 196 9.4 Summary 200 appendix A JUnit primer 202 appendix B Extending JUnit 209 index 217 www.it-ebooks.info www.it-ebooks.info xv preface On the night

Ngày đăng: 24/04/2014, 15:07

Mục lục

  • Effective Unit Testing

  • brief contents

  • contents

  • preface

  • acknowledgments

  • about this book

    • Audience

    • Roadmap

    • Code conventions

    • Code downloads

    • What’s next?

    • Author Online

    • about the cover illustration

    • Part 1 Foundations

      • 1 The promise of good tests

        • 1.1 State of the union: writing better tests

        • 1.2 The value of having tests

          • 1.2.1 Factors of productivity

          • 1.2.2 The curve of design potential

          • 1.3 Tests as a design tool

            • 1.3.1 Test-driven development

            • 1.3.2 Behavior-driven development

            • 1.4 Summary

            • 2 In search of good

              • 2.1 Readable code is maintainable code

              • 2.2 Structure helps make sense of things

Tài liệu cùng người dùng

Tài liệu liên quan