Pragmatic Unit Testing in Java 8 with JUnit

Takeaway Skills

Learn how to effectively test Java applications using JUnit

Get to know the core quality principles of unit testing

Master writing cleaner and refactored JUnit tests

Course Overview

In this course, you will learn how to write a unit test for Java applications using JUnit. You’ll start by covering unit-testing foundations, which provide you with a starter set of information about writing basic tests in JUnit. You’ll learn about JUnit organization and assertions, and you’ll pick up a few core quality practices for unit testing such as the Right BICEP and the CORRECT way. Towards the end, the bigger design picture focuses on the relevance of design to unit testing and vice versa. You’ll refactor your tests, and you’ll learn how to use mock objects to deal with trouble-some dependencies.

Course Contents

  1. Before We Begin
  • Why This Course?
  • Course Structure
  • Why Unit Testing?

2. JUnit Test Foundations

  • Reasons to Write Unit Tests
  • Introduction to Building JUnit Test
  • Our First Passing Test
  • Arrange, Act, and Assert Your Way to a Test
  • Understanding What We’re Testing: The Profile Class
  • Let’s Write Tests
  • Initializing Tests with @Before Methods
  • Quiz on JUnit Test Bits

3. Digging Deeper into JUnit Assertions

  • Introduction to Assertions in JUnit
  • A Classic-Style Assertion: assertTrue
  • Hamcrest Assertions
  • Decorators
  • Comparing Two Floating-Point Numbers
  • Assertion Messages
  • Testing the Expected Exceptions
  • Expected Exceptions using JUnit
  • Quiz Time

4. Organizing Your Tests

  • Follow the AAA Pattern
  • Test Behaviors not Methods
  • Relationship Between Test and Production Code
  • Focused and Single-purpose Tests
  • Test Documentation
  • Using Annotations
  • Green Is Good
  • Quiz Time

5. Mastering Manic Mnemonics!

  • FIRST: Properties of Good Tests
  • [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
  • Quiz Time

6. What to Test: The Right-BICEP

  • The Right-BICEP
  • [Right]-BICEP: Are the Results Right?
  • Right-[B]ICEP: Boundary Conditions
  • Right-B[I]CEP: Checking Inverse Relationships
  • Right-BI[C]EP: Cross-Checking Using Other Means
  • Right-BIC[E]P: Forcing Error Conditions
  • Right-BICE[P]: Performance Characteristics
  • Quiz time

7. Boundary Conditions: The CORRECT Way

  • The CORRECT Way
  • [C]ORRECT: [C]onformance
  • C[O]RRECT: [O]rdering
  • CO[R]RECT: [R]ange
  • COR[R]ECT: [R]eference
  • CORR[E][C]T: [C]ardinality and [E]xistence
  • CORREC[T]: [T]ime
  • Quiz time

8. The Bigger Design Picture

  • Refactoring to Cleaner Code
  • Finding Better Homes for Our Methods
  • Automated and Manual Refactorings
  • How much Refactoring?
  • Quiz time

9. Bigger Design Issues

  • SOLID class design principles
  • The SRP and Profile class
  • Command-query separation principle
  • Test Maintenance Cost
  • Other Design Thoughts
  • Quiz Time

10. Using Mock Objects

  • A Testing Challenge
  • Replacing Troublesome Behavior with Stubs
  • Changing Our Design to Support Testing
  • Simplifying Testing using a Mock Tool
  • One Last Simplification: Introducing an Injection Tool
  • What’s Important to Get Right When Using Mocks?
  • Quiz Time

11. 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
  • Test Smell: Implicit Meaning and Misleading Organization
  • Adding a New Test
  • Quiz Time

12. The Bigger Unit-Testing Picture

  • Test-Driven Development
  • TDD Cycle
  • Smallest Possible Increment
  • Code Refactoring
  • Another Small Increment
  • Supporting Multiple Answers: A Small Design Detour
  • Expanding the Interface
  • Last Tests
  • Tests As Documentation
  • Quiz Time

13. Testing Some Tough Stuff

  • Testing Multithreaded Code
  • Extracting Application Logic
  • Redesigning the Threading Logic
  • Testing Databases
  • The Data Problem
  • Cleaning the Database and Mocking the Controller

14. Testing on a Project

  • Coming up to Speed
  • One Team, One Unit
  • Convergence with Continuous Integration
  • Code Coverage

15. Wrapping Up

  • Conclusion

16. Appendix – Setting up JUnit

  • IntelliJ IDEA
  • NetBeans

How You’ll Learn

Hands-on Coding Environments

You don’t get better at swimming by watching others. Coding is no different. Practice as you learn with live code environments inside your browser.

2x Faster Than Videos

Videos are holding you back. The average video tutorial is spoken at 150 words per minute, while you can read at 250. That‘s why our courses are text-based.

No Set-up Required

Start learning immediately instead of fiddling with SDKs and IDEs. It‘s all on the cloud.

Progress You Can Show

Built in assessments let you test your skills. Completion certificates let you show them off.

Leave a Reply

Your email address will not be published. Required fields are marked *