You are previewing Pragmatic Unit Testing in Java 8 with JUnit.
O'Reilly logo
Pragmatic Unit Testing in Java 8 with JUnit

Book Description

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.

Table of Contents

  1. Pragmatic Unit Testing in Java 8 with JUnit
    1. For the Best Reading Experience...
    2. Table of Contents
    3. Foreword
    4. Early praise for Pragmatic Unit Testing in Java 8 with JUnit
    5. Preface
      1. Why Unit Testing
      2. Who This Book Is For
      3. What You Need
      4. How to Use This Book
      5. Code and Online Resources
      6. Acknowledgments
    6. Part 1: Unit-Testing Foundations
      1. Chapter 1: Building Your First JUnit Test
        1. Reasons to Write a Unit Test
        2. Learning JUnit Basics: Our First Passing Test
        3. Arrange, Act, and Assert Your Way to a Test
        4. Is the Test Really Testing Anything?
        5. After
      2. Chapter 2: Getting Real with JUnit
        1. Understanding What We’re Testing: The Profile Class
        2. Determining What Tests We Can Write
        3. Covering One Path
        4. Tackling a Second Test
        5. Initializing Tests with @Before Methods
        6. How Ya Feelin’ Now?
        7. After
      3. Chapter 3: Digging Deeper into JUnit Assertions
        1. Assertions in JUnit
        2. Three Schools for Expecting Exceptions
        3. After
      4. Chapter 4: Organizing Your Tests
        1. Keeping Tests Consistent with AAA
        2. Testing Behavior Versus Testing Methods
        3. Relationship Between Test and Production Code
        4. The Value of Focused, Single-Purpose Tests
        5. Tests as Documentation
        6. More on @Before and @After (Common Initialization and Cleanup)
        7. Green Is Good: Keeping Our Tests Relevant
        8. After
    7. Part 2: Mastering Manic Mnemonics!
      1. Chapter 5: FIRST Properties of Good Tests
        1. FIRST It Helps to Remember That Good Tests Are FIRST
        2. [F ] IRST: [F ] ast!
        3. F[I ] RST: [I ] solate Your Tests
        4. FI[R ] ST: Good Tests Should Be [R ] epeatable
        5. FIR[S ] T: [S ] elf-Validating
        6. FIRS[T ] : [T ] imely
        7. After
      2. Chapter 6: What to Test: The Right-BICEP
        1. [Right ] -BICEP: Are the Results Right?
        2. Right-[B ] ICEP: Boundary Conditions
        3. Remembering Boundary Conditions with CORRECT
        4. Right-B[I ] CEP: Checking Inverse Relationships
        5. Right-BI[C ] EP: Cross-Checking Using Other Means
        6. Right-BIC[E ] P: Forcing Error Conditions
        7. Right-BICE[P ] : Performance Characteristics
        8. After
      3. Chapter 7: Boundary Conditions: The CORRECT Way
        1. [C ] ORRECT: [C ] onformance
        2. C[O ] RRECT: [O ] rdering
        3. CO[R ] RECT: [R ] ange
        4. COR[R ] ECT: [R ] eference
        5. CORR[E ] CT: [E ] xistence
        6. CORRE[C ] T: [C ] ardinality
        7. CORREC[T ] : [T ] ime
        8. After
    8. Part 3: The Bigger Design Picture
      1. Chapter 8: Refactoring to Cleaner Code
        1. A Little Bit o’ Refactor
        2. Finding Better Homes for Our Methods
        3. Automated and Manual Refactorings
        4. Taking Refactoring Too Far?
        5. After
      2. Chapter 9: Bigger Design Issues
        1. The Profile Class and the SRP
        2. Extracting a New Class
        3. Command-Query Separation
        4. The Cost of Maintaining Unit Tests
        5. Other Design Thoughts
        6. After
      3. Chapter 10: Using Mock Objects
        1. A Testing Challenge
        2. Replacing Troublesome Behavior with Stubs
        3. Changing Our Design to Support Testing
        4. Adding Smarts to Our Stub: Verifying Parameters
        5. Simplifying Testing Using a Mock Tool
        6. One Last Simplification: Introducing an Injection Tool
        7. What’s Important to Get Right When Using Mocks
        8. After
      4. Chapter 11: Refactoring Tests
        1. Searching for an Understanding
        2. Test Smell: Unnecessary Test Code
        3. Test Smell: Missing Abstractions
        4. Test Smell: Irrelevant Information
        5. Test Smell: Bloated Construction
        6. Test Smell: Multiple Assertions
        7. Test Smell: Irrelevant Details in Test
        8. Test Smell: Misleading Organization
        9. Test Smell: Implicit Meaning
        10. Adding a New Test
        11. After
    9. Part 4: The Bigger Unit-Testing Picture
      1. Chapter 12: Test-Driven Development
        1. The Primary Benefit of TDD
        2. Starting Simple
        3. Adding Another Increment
        4. Cleaning Up Our Tests
        5. Another Small Increment
        6. Supporting Multiple Answers: A Small Design Detour
        7. Expanding the Interface
        8. Last Tests
        9. Tests As Documentation
        10. The Rhythm of TDD
        11. After
      2. Chapter 13: Testing Some Tough Stuff
        1. Testing Multithreaded Code
        2. Testing Databases
        3. After
      3. Chapter 14: Testing on a Project
        1. Coming up to Speed
        2. Getting on the Same Page with Your Team
        3. Convergence with Continuous Integration
        4. Code Coverage
        5. After
    10. Appendix 1: Setting Up JUnit in IntelliJ IDEA and NetBeans
      1. IntelliJ IDEA
      2. NetBeans
      3. You May Be Interested In…