Unit testing: Apex practice drills
Apex test classes that fail when the code is wrong: assertions, test data, mocks and callout mocks.
Intermediate · Check and Run with Apex Path ($19 a month).
- Assert service outcomes Beginner · 10 min
A test needs an expected value to compare with the real result.
- Create isolated test data Beginner · 12 min
A test should create the records it needs.
- Build a test data factory Intermediate · 12 min
A test data factory is a public @IsTest class with helpers that build records for many tests.
- Test success and exceptions Intermediate · 15 min
Test the happy path and the error path.
- Check partial DML results Intermediate · 15 min
Database.insert(rows, false) returns one SaveResult per row.
- Reset limits around the act Intermediate · 15 min
Test.startTest() gives the code under test a fresh set of governor limits.
- Prove bulk behavior Intermediate · 15 min
Bulk tests use real batch sizes, like 200 records, and check every result.
- Use a fake collaborator Intermediate · 18 min
extends makes your class a child; override replaces a parent method marked virtual.
- Mock an HTTP callout Intermediate · 16 min
Tests cannot make real HTTP callouts.
- Share setup and run as another user Intermediate · 18 min
@TestSetup runs once per class, and every test method sees its rows.