Pragmatic Unit Testing: In Java with JUnit

Paperback
from $0.00

Author: Andrew Hunt

ISBN-10: 0974514012

ISBN-13: 9780974514017

Category: Quality Control & Testing - Programming

Learn how to improve your Java coding skills using unit testing. Despite it's name, unit testing is really a coding technique, not a testing technique. Unit testing is done by programmers, for programmers. It's primarily for our benefit: we get improved confidence in our code, better ability to make deadlines, less time spent in the debugger, and less time beating on the code to make it work correctly.\ This book shows how to write tests, but more importantly, it goes where other books fear...

Search in google:

Learn how to improve your Java coding skills using unit testing. Despite it's name, unit testing is really a coding technique, not a testing technique. Unit testing is done by programmers, for programmers. It's primarily for our benefit: we get improved confidence in our code, better ability to make deadlines, less time spent in the debugger, and less time beating on the code to make it work correctly. This book shows how to write tests, but more importantly, it goes where other books fear to tread and gives you concrete advice and examples of what to test--the common things that go wrong in all of our programs. Discover the tricky hiding places where bugs breed, and how to catch them using the freely available JUnit framework. It's easy to learn how to think of all the things in your code that are likely to break. We'll show you how with helpful mnemonics, summarized in a handy tip sheet (also available from our www.pragmaticprogrammer.com website) to help you remember all this stuff. With this book you will: Write better code, and take less time to write it Discover the tricky places where bugs breed Learn how to think of all the things that could go wrong Test individual pieces of code without having to include the whole project Test effectively with the whole team We'll also cover how to use Mock Objects for testing, how to write high quality test code, and how to use unit testing to improve your design skills. We'll show you frequent "gotchas"--along with the fixes--to save you time when problems come up. We'll show you how with helpful mnemonics, summarized in a handy tip sheet (also available from our www.pragmaticprogrammer.com website). But thebest part is that you don't need a sweeping mandate to change your whole team or your whole company. You don't need to adopt Extreme Programming or Test-Driven Development, or change your development process in order to reap the proven benefits of unit testing. You can start unit testing, the pragmatic way, right away.

About the Starter KitxiPrefacexiii1Introduction11.1Coding With Confidence21.2What is Unit Testing?31.3Why Should I Bother with Unit Testing?41.4What Do I Want to Accomplish?51.5How Do I Do Unit Testing?71.6Excuses For Not Testing71.7Roadmap122Your First Unit Tests132.1Planning Tests142.2Testing a Simple Method152.3More Tests203Writing Tests in JUnit213.1Structuring Unit Tests213.2JUnit Asserts223.3JUnit Framework263.4JUnit Test Composition273.5JUnit Custom Asserts323.6JUnit and Exceptions333.7More on Naming353.8JUnit Test Skeleton354What to Test: The Right-BICEP374.1Are the Results Right?384.2Boundary Conditions414.3Check Inverse Relationships424.4Cross-check Using Other Means424.5Force Error Conditions434.6Performance Characteristics445Correct Boundary Conditions475.1Conformance485.2Ordering495.3Range515.4Reference545.5Existence555.6Cardinality565.7Time585.8Try It Yourself606Using Mock Objects656.1Simple Stubs666.2Mock Objects676.3Testing a Servlet716.4Easy Mock Objects747Properties of Good Tests797.1Automatic807.2Thorough817.3Repeatable837.4Independent837.5Professional847.6Testing the Tests868Testing on a Project898.1Where to Put Test Code898.2Test Courtesy938.3Test Frequency948.4Tests and Legacy Code958.5Tests and Reviews989Design Issues1019.1Designing for Testability1019.2Refactoring for Testing1039.3Testing the Class Invariant1149.4Test-Driven Design1179.5Testing Invalid Parameters119AGotchas121A.1As Long As The Code Works121A.2"Smoke" Tests121A.3"Works On My Machine"122A.4Floating-Point Problems122A.5Tests Take Too Long123A.6Tests Keep Breaking123A.7Tests Fail on Some Machines124A.8My main is Not Being Run125BInstalling JUnit127B.1Command-line installation128B.2Does it work?129CJUnit Test Skeleton131C.1Helper Class133C.2Basic Template133DResources137D.1On The Web137D.2Bibliography139ESummary: Pragmatic Unit Testing141FAnswers to Exercises143