Using Nullables
In this module, you’ll learn how to use Nullables to create fast, reliable tests of application-level code that depends on infrastructure. You’ll test-drive the implementation of HomePageController
, the controller for a web page that uses a ROT-13 microservice to encode the user’s text.
Concepts
Download the slides and transcript here.
Direct links to patterns discussed in this module:
- Narrow Tests
- State-Based Tests
- Overlapping Sociable Tests
- Signature Shielding
- Parameterless Instantiation
- Nullables
- Configurable Responses
- Output Tracking
- Behavior Simulation
Primers
You may wish to familiarize yourself with these primers before starting on the exercises:
- JavaScript Basics
- Introduced in challenge #1:
- Introduced in challenge #4:
- Introduced in challenge #9:
Exercise Setup
Start with the Pre-Course Setup. Then:
1. Check out the code
- Check out the exercise branch:
- JavaScript:
git checkout using-nullables-js
- TypeScript:
git checkout using-nullables-ts
- JavaScript:
- Create a custom branch for your changes:
git checkout -b my-using-nullables
2. Prepare to start working
- Open the exercise files:
src/www/home_page/_home_page_controller_test.js
(or.ts
)src/www/home_page/home_page_controller.js
(or.ts
)
- Run the build watcher from the root of the repository:
- Windows:
.\watch.cmd quick
- Mac/Linux:
./watch.sh quick
- Windows:
- Confirm that the build runs and ends with
BUILD OK
.
Exercises
The course is designed to have more exercises than you can finish in a single session, so don’t worry about finishing everything. Instead, work at your own pace and focus on understanding the material. If you get to the end of challenge #3, you’ll have covered the most important information.
- Challenge #1: Using Nullables
- Challenge #2a: Tracking Requests
- Challenge #2b: Dynamic Configuration
- Challenge #2c: Parsing the Request Body
- Challenge #3: Configuring Responses
- Challenge #4: Signature Shielding
- Challenge #5: Logging
- Challenge #6: Refactoring
- Challenge #7: Service Errors
- Challenge #8: Design Changes
- Challenge #9: Timeouts
- Bonus Challenges