About This Title

Pages: 234
Published: March 2015
ISBN: 9781941222591
In Print

Skill Level Meter

Pragmatic Unit Testing in Java 8 with JUnit

by Jeff Langr, with Andy Hunt and Dave Thomas

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.


This book uses JUnit 4.


eBook Formats:

  • PDF for desktop/tablets

  • epub for Apple Books, e-readers

  • mobi for Kindle readers

Get all eBook formats here for $22.95 (USD)

Add to Cart we accept visa, mastercard, amex, discover, paypal


Paperback Formats:

Please support indie bookstores!
Find indie bookstores in the U.S. Find indie bookstores around the world.


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!

Resources

Releases:

  • P1.0 2015/03/17
  • B5.0 2015/02/25
  • B4.0 2015/01/14
  • B3.0 2014/12/16

Contents & Extracts

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
    • Organizing Your Tests
      • Keeping Tests Consistent with AAA
      • Testing Behavior Versus Testing Methods
      • Relationship Between Test and Production Code
      • The Value of Focused, Single-Purpose Tests
      • Tests as Documentation
      • More on Before and After (Common Initialization and Cleanup)
      • Green Is Good: Keeping Our Tests Relevant
      • After
  • 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[R]ST: Good Tests Should Be [R]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 CORRECT
      • Right-B[I]CEP: Checking Inverse Relationships
      • Right-BICEP: Cross-Checking Using Other Means
      • Right-BIC[E]P: Forcing Error Conditions
      • Right-BICE[P]: Performance Characteristics
      • After
    • Boundary Conditions–The CORRECT Way
      • [C]ORRECT: [C]onformance
      • C[O]RRECT: [O]rdering
      • CORRECT: [R]ange
      • COR[R]ECT: [R]eference
      • CORR[E]CT: [E]xistence
      • CORRE[C]T: [C]ardinality
      • CORREC[T]: [T]ime
      • After
  • The Bigger Design Picture
    • Refactoring to Cleaner Code excerpt
      • A Little Bit o’ Refactor
      • Finding Better Homes for Our Methods
      • Automated and Manual Refactorings
      • Taking Refactoring Too Far?
      • After
    • Bigger Design Issues
      • The Profile Class and the SRP
      • Extracting a New Class
      • Command-Query Separation
      • The Cost of Maintaining Unit Tests
      • Other Design Thoughts
      • After
    • Using Mock Objects
      • A Testing Challenge
      • Replacing Troublesome Behavior with 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
      • Searching for an Understanding
      • Test Smell: Unnecessary Test Code
      • Test Smell: Missing Abstractions
      • Test Smell: Irrelevant Information
      • Test Smell: Bloated Construction
      • Test Smell: Multiple Assertions
      • Test Smell: Irrelevant Details in Test
      • Test Smell: Misleading Organization
      • Test Smell: Implicit Meaning
      • Adding a New Test
      • After
  • 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 Multithreaded Code
      • Testing Databases
      • After
    • Testing on a Project
      • Coming Up to Speed
      • Get on the Same Page With Your Team
      • Convergence With Continuous Integration
      • Code Coverage
      • After
    • Setting UP JUnit in IntelliJ IDEA and NetBeans
      • IntelliJ IDEA
      • NetBeans

Author

Jeff Langr is a veteran software developer with well over three decades experience building software and helping others learn how to do so. Jeff develops software for Outpace Systems, Inc., and still provides help to customers through Langr Software Solutions, Inc. Jeff’s prior Pragmatic Bookshelf titles include Agile in a Flash (with Tim Ottinger) and Modern C[]{.underline} Programming with Test-Driven Development.

Andy Hunt has written and co-written over a half-dozen previous titles, including the classic The Pragmatic Programmer, Practices of an Agile Developer, Pragmatic Thinking & Learning, and Learn to Program with Minecraft Plugins, and regularly speaks at conferences on software development around the world.

Dave Thomas is a programmer who likes to evangelize cool stuff. He cowrote The Pragmatic Programmer, and was one of the creators of the Agile Manifesto. His book Programming Ruby introduced the Ruby language to the world, and Agile Web Development with Rails helped kickstart the Rails revolution.

eBook Formats:

  • PDF for desktop/tablets

  • epub for Apple Books, e-readers

  • mobi for Kindle readers

Get all eBook formats here for $22.95 (USD)

Add to Cart we accept visa, mastercard, amex, discover, paypal


Paperback Formats:

Please support indie bookstores!
Find indie bookstores in the U.S. Find indie bookstores around the world.

Related Titles:

Skill Level Meter

About This Title

Pages: 234
Published: March 2015
ISBN: 9781941222591
Edition: 1
In Print