---
url: https://apexfluently.beyondthecloud.dev/libraries/test-lib.md
description: >-
  Create Apex test data with a fluent API. Builder and Mocker patterns,
  templates, randomizers, and relationship mocking without DML.
---

# Test Lib

Easy test data creation in Apex.

::: info Documentation
You can find the full documentation at [testlib.beyondthecloud.dev](https://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();
```

## Documentation

* [GitHub Repository](https://github.com/beyond-the-cloud-dev/test-lib)

## Installation

* [Installation Guide](https://testlib.beyondthecloud.dev/installation.html)
* [Copy and Deploy](https://github.com/beyond-the-cloud-dev/test-lib/tree/main/force-app/main/default/classes)
