ApexSensei

All drills

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).

  1. Assert service outcomes Beginner · 10 min

    A test needs an expected value to compare with the real result.

  2. Create isolated test data Beginner · 12 min

    A test should create the records it needs.

  3. 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.

  4. Test success and exceptions Intermediate · 15 min

    Test the happy path and the error path.

  5. Check partial DML results Intermediate · 15 min

    Database.insert(rows, false) returns one SaveResult per row.

  6. Reset limits around the act Intermediate · 15 min

    Test.startTest() gives the code under test a fresh set of governor limits.

  7. Prove bulk behavior Intermediate · 15 min

    Bulk tests use real batch sizes, like 200 records, and check every result.

  8. Use a fake collaborator Intermediate · 18 min

    extends makes your class a child; override replaces a parent method marked virtual.

  9. Mock an HTTP callout Intermediate · 16 min

    Tests cannot make real HTTP callouts.

  10. Share setup and run as another user Intermediate · 18 min

    @TestSetup runs once per class, and every test method sees its rows.

Start practicing free