The Pragmatic Programmers classic is back! Freshly updated for modern software development, Pragmatic Unit Testing in Java 8 With JUnit teaches you how to write and run easily maintained unit tests in JUnit with confidence. You’ll learn mnemonics to help you know what tests to write, how to remember all the boundary conditions, and what the qualities of a good test are. You’ll see how unit tests can pay off by allowing you to keep your system code clean, and you’ll learn how to handle the stuff that seems too tough to test.
Buy Now
This title is currently available in Beta. Buy the eBook now, and you'll be able to download successive releases of the eBook as the authors add material and correct mistakes. You'll get the final eBook when the book is finished.
If you buy the combo pack (Beta eBook + finished Paper Book) now, you'll get the Beta eBook immediately. You'll get the finished paper book when it's released (we're currently estimating 2015-04-10, but these dates can change).
About this Book
- 220 pages (est)
- Published:
- Release: B1.0 (2014-11-18)
- ISBN: 978-1-94122-259-1
Pragmatic Unit Testing in Java 8 With JUnit steps you through all the important unit testing topics. If you’ve never written a unit test, you’ll see screen shots from Eclipse, IntelliJ IDEA, and NetBeans that will help you get past the hard part—getting set up and started.
Once past the basics, you’ll learn why you want to write unit tests and how to effectively use JUnit. But the meaty part of the book is its collected unit testing wisdom from people who’ve been there, done that on production systems for at least 15 years: veteran author and developer Jeff Langr, building on the wisdom of Pragmatic Programmers Andy Hunt and Dave Thomas. You’ll learn:
- How to craft your unit tests to minimize your effort in maintaining them.
- How to use unit tests to help keep your system clean.
- How to test the tough stuff.
- Memorable mnemonics to help you remember what’s important when writing unit tests.
- How to help your team reap and sustain the benefits of unit testing.
You won’t just learn about unit testing in theory—you’ll work through numerous code examples. When it comes to programming, hands-on is the only way to learn!
What You Need
You’ll need the Java SDK (Software Development Kit) version 8 or higher to work through the examples in the book. You’ll also want an IDE (Integrated Development Environment) in which to build code. While most of the book doesn’t assume use of any specific IDE, you’ll find a number of “getting started” screen shots to help you if you’re using Eclipse, IntelliJ IDEA, or NetBeans. Chances are good you’ll be working in one of those!
Contents and Extracts
This book is currently in beta, so the contents and extracts will change as the book is developed.
Preface- Unit Testing Foundations
- Building Your First JUnit Test excerpt
- Reasons to Write a Unit Test
- Learning JUnit Basics: Your First Passing Test
- Arrange, Act, and Assert Your Way to a Test
- Is the Test Really Testing Anything?
- After
- Getting Real with JUnit
- Understanding What We’re Testing: The Profile Class
- Determining What Tests We Can Write
- Covering One Path
- Tackling a Second Test
- Initializing Tests with @Before Methods
- How Ya Feelin’ Now?
- After
- Digging Deeper into JUnit Assertions
- Assertions in JUnit
- Three Schools for Expecting Exceptions
- After
- Unit Test Structure and Organization
- Keeping Tests Consistent with AAA
- Testing Behavior vs. Testing Methods
- Understanding the Distinction Between Tests and Targets
- The Value of Focused, Single-Purpose Tests
- Tests as Documentation
- More on @Before and @After (Common Initialization and Cleanup)
- Green is Good: Keeping Your Tests Relevant
- After
- Building Your First JUnit Test excerpt
- Mastering Manic Mnemonics!
- FIRST Properties of Good Tests
- FIRST It Helps to Remember That Good Tests Are FIRST
- [F]IRST: [F]ast!
- F[I]RST: [I]solate Your Tests
- FI®ST: Good Tests Should Be®epeatable
- FIR[S]T: [S]elf-Validating
- FIRS[T]: [T]imely
- After
- What to Test: The Right-BICEP excerpt
- [Right] BICEP—Are the Results Right?
- Right [B]ICEP—Boundary Conditions
- Remembering Boundary Conditions with the CORRECT Mnemonic
- Right B[I]CEP—Check Inverse Relationships
- Right BI©EP—Cross-check Using Other Means
- Right-BIC[E]P—Force Error Conditions
- Right-BICE[P]—Performance Characteristics
- After
- Boundary Conditions–The CORRECT Way
- [C]ORRECT: [C]onformance
- C[O]RRECT: [O]rdering
- CO®RECT: [R]ange
- COR[R]ECT: [R]eference
- CORR[E]CT: [E]xistence
- CORRE[C]T: [C]ardinality
- CORREC[T]: [T]ime
- After
- FIRST Properties of Good Tests
- The Bigger Design Picture
- Refactoring to Cleaner Code excerpt
- A Little Bit o’ Refactor
- Finding Better Homes for Your Methods
- Inlining Expressions to Reduce Clutter
- After
- Bigger Design Issues
- Revisiting the Profile Class
- Extracting a New Class
- Command-Query Separation
- The Cost of Maintaining Unit Tests
- After
- Using Mock Objects
- A Testing Challenge
- Stubs
- Changing Our Design to Support Testing
- Adding Smarts to Our Stub: Verifying Parameters
- Simplifying Testing Using a Mock Tool
- One Last Simplification: Introducing an Injection Tool
- What’s Important to Get Right When Using Mocks
- After
- Refactoring Tests
- Refactoring to Cleaner Code excerpt
- The Bigger Unit Testing Picture
- Test-Driven Development
- The Primary Benefit of TDD
- Starting Simple
- Adding Another Increment
- Cleaning Up Our Tests
- Another Small Increment
- Supporting Multiple Answers: A Small Design Detour
- Expanding the Interface
- Last Tests
- Tests As Documentation
- The Rhythm of TDD
- After
- Testing Some Tough Stuff
- Testing on a Project
- Coming Up to Speed
- Get on the Same Page With Your Team
- Convergence With Continuous Integration
- Code Coverage
- After
- Test-Driven Development