Log In
Join
for free
Back To Course Home
Pragmatic Unit Testing in Java 8 with JUnit
0% completed
Before We Begin
Why This Course?
Course Structure
Why Unit Testing?
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
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
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
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
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
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
The Bigger Design Picture
Refactoring to Cleaner Code
Finding Better Homes for Our Methods
Automated and Manual Refactorings
How much Refactoring?
Quiz time
Bigger Design Issues
SOLID class design principles
The SRP and Profile class
Command-query separation principle
Test Maintenance Cost
Other Design Thoughts
Quiz Time
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
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
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
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
Testing on a Project
Coming up to Speed
One Team, One Unit
Convergence with Continuous Integration
Code Coverage
Wrapping Up
Conclusion
Appendix - Setting up JUnit
IntelliJ IDEA
NetBeans
[F]IRST: [F]ast
Learn the importance of running tests efficiently.
We'll cover the following
Slow and fast test
Optimizing for time
Clean design
Example: StatCompiler class
StatCompiler explanation
Testing challenge
Better approach
Minimizing dependencies
Slow and fast test
Get hands-on with 1400+ tech skills courses.
Start Free Trial