ApexSensei

All drills

Prove it with tests: Apex practice drills

Apex test classes that fail when the code is wrong: assertions, test data, mocks and callout mocks.

10 drills · Intermediate · Free to read, run with Apex Path ($19/month after a 7-day trial)

  1. Assert service outcomes (Beginner, 10 min)
    Write a test helper that fails the test when a service returns the wrong label.
  2. Create isolated test data (Beginner, 12 min)
    Insert your own test Account, then read it back from the database by its Id.
  3. Build a test data factory (Intermediate, 12 min)
    Build a test data factory that inserts any number of Accounts with one DML statement.
  4. Test success and exceptions (Intermediate, 15 min)
    Write verifiers that fail on a wrong amount, a wrong error message or a missing error.
  5. Check partial DML results (Intermediate, 15 min)
    Insert a good and a bad Account with partial DML, and write a verifier that fails on wrong SaveResults.
  6. Reset limits around the act (Intermediate, 15 min)
    Use Test.startTest and Test.stopTest to count only the queries the code under test runs.
  7. Prove bulk behavior (Intermediate, 15 min)
    Write a list verifier that checks the size and every item, and fails on a wrong 200-item list.
  8. Use a fake collaborator (Intermediate, 18 min)
    Replace an outside gateway with a test fake that records calls and can fail once on purpose.
  9. Mock an HTTP callout (Intermediate, 16 min)
    Implement HttpCalloutMock and register it with Test.setMock so a client can be tested offline.
  10. Share setup and run as another user (Intermediate, 18 min)
    Create a fixture user and Account in @TestSetup, then use System.runAs to insert a Task as that user.

Start practicing free