Pragmatic Unit Testing: In Java with JUnit / Edition 1
  • Alternative view 1 of Pragmatic Unit Testing: In Java with JUnit / Edition 1
  • Alternative view 2 of Pragmatic Unit Testing: In Java with JUnit / Edition 1

Pragmatic Unit Testing: In Java with JUnit / Edition 1

4.0 1
by Andy Hunt, Dave Thomas
     
 

ISBN-10: 0974514012

ISBN-13: 9780974514017

Pub. Date: 09/28/2003

Publisher: Pragmatic Programmers, LLC, The

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

Overview

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.comwebsite).But the best 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.

Product Details

ISBN-13:
9780974514017
Publisher:
Pragmatic Programmers, LLC, The
Publication date:
09/28/2003
Series:
Pragmatic Programmers Series
Edition description:
New Edition
Pages:
176
Product dimensions:
7.48(w) x 8.94(h) x 0.59(d)

Table of Contents

About the Starter Kitxi
Prefacexiii
1Introduction1
1.1Coding With Confidence2
1.2What is Unit Testing?3
1.3Why Should I Bother with Unit Testing?4
1.4What Do I Want to Accomplish?5
1.5How Do I Do Unit Testing?7
1.6Excuses For Not Testing7
1.7Roadmap12
2Your First Unit Tests13
2.1Planning Tests14
2.2Testing a Simple Method15
2.3More Tests20
3Writing Tests in JUnit21
3.1Structuring Unit Tests21
3.2JUnit Asserts22
3.3JUnit Framework26
3.4JUnit Test Composition27
3.5JUnit Custom Asserts32
3.6JUnit and Exceptions33
3.7More on Naming35
3.8JUnit Test Skeleton35
4What to Test: The Right-BICEP37
4.1Are the Results Right?38
4.2Boundary Conditions41
4.3Check Inverse Relationships42
4.4Cross-check Using Other Means42
4.5Force Error Conditions43
4.6Performance Characteristics44
5Correct Boundary Conditions47
5.1Conformance48
5.2Ordering49
5.3Range51
5.4Reference54
5.5Existence55
5.6Cardinality56
5.7Time58
5.8Try It Yourself60
6Using Mock Objects65
6.1Simple Stubs66
6.2Mock Objects67
6.3Testing a Servlet71
6.4Easy Mock Objects74
7Properties of Good Tests79
7.1Automatic80
7.2Thorough81
7.3Repeatable83
7.4Independent83
7.5Professional84
7.6Testing the Tests86
8Testing on a Project89
8.1Where to Put Test Code89
8.2Test Courtesy93
8.3Test Frequency94
8.4Tests and Legacy Code95
8.5Tests and Reviews98
9Design Issues101
9.1Designing for Testability101
9.2Refactoring for Testing103
9.3Testing the Class Invariant114
9.4Test-Driven Design117
9.5Testing Invalid Parameters119
AGotchas121
A.1As Long As The Code Works121
A.2"Smoke" Tests121
A.3"Works On My Machine"122
A.4Floating-Point Problems122
A.5Tests Take Too Long123
A.6Tests Keep Breaking123
A.7Tests Fail on Some Machines124
A.8My main is Not Being Run125
BInstalling JUnit127
B.1Command-line installation128
B.2Does it work?129
CJUnit Test Skeleton131
C.1Helper Class133
C.2Basic Template133
DResources137
D.1On The Web137
D.2Bibliography139
ESummary: Pragmatic Unit Testing141
FAnswers to Exercises143

Customer Reviews

Average Review:

Write a Review

and post it to your social network

     

Most Helpful Customer Reviews

See all customer reviews >

Pragmatic Unit Testing in Java with JUnit 4 out of 5 based on 0 ratings. 1 reviews.
Guest More than 1 year ago
Unit testing is `by the developer for the developer¿, it¿s a tool used to ensure code written withstand the tests of time through changes in requirements, bug fixes, and added functionality. Unit (leveraging JUnit) tests are written in Java (there is also a C# version of this text) that live within a testing framework called JUnit and are executed against our application code on a periodic basis (whether that be hourly, daily or at deployment, its up to you) to validate that the code under test continues to perform as per its requirements throughout the project lifecycle. This way we write code that conforms to the `ilities¿, reliability, repeatability, maintainability, and scalability. The book takes you through a nicely sculpted path of learning from the initial `baby-steps¿ Unit testing examples to the more complex day to day challenges of writing loosely coupled Unit tests (using MockObjects) in surrounding environments that include things such as the network, database, or even a Servlet Container. And while winding its way down this path we are also introduced to pearls of wisdom in Chapters titled, `What to Test¿, `Using MockObjects¿, `Properties of Good Tests¿, `Testing on a Project¿, `Design Issues¿, and `Gotchas¿. And finally at the end of the path or text we find a list of very useful testing resources, the text summary, and answers to all exercise questions in the book. This is a definite must have for the programmers tool-kit.