Test Lib
Easy test data creation in Apex.
Documentation
You can find the full documentation at testlib.beyondthecloud.dev.
What Does It Solve?
- Complex Test Data Creation - Every test method repeats the same record setup boilerplate.
- Long-Running Unit Tests - Inserting records only to satisfy a required field slows down the whole test suite.
- Hard-To-Mock Relationships - Parent lookups and child collections are read-only and cannot be assigned directly.
Why Test Lib?
- Builder Pattern - Create real database records with
buildAndInsert(). - Mocker Pattern - Create in-memory records without DML operations.
- Templates - Predefined configurations for common scenarios.
- Randomizers - Generate unique values for bulk record creation.
- Relationships - Mock parent lookups and child collections.
- Fluent API - Readable, chainable test code that describes the scenario.
Quick Start
apex
// Builder - creates real records in database
Account acc = (Account) AccountTestModule.Builder()
.enterprise()
.buildAndInsert();
// Mocker - creates in-memory records (no DML)
Contact con = (Contact) ContactTestModule.Mocker()
.setFakeId()
.set('Account.Name', acc.Name)
.build();