---
title: "Discussion on \"Apex Test Data Factories: Patterns That Prevent Flaky Tests\" | Hashnode"
description: "Discussion on \"Apex Test Data Factories: Patterns That Prevent Flaky Tests\". Every Apex test class needs to create its own data. Done badly, the test setup is duplicated across hundreds of files, breaks when a required field is added, and produces flaky tests that pass in one sandbox and fail in another."
url: "https://hashnode.com/posts/apex-test-data-factories-patterns-that-prevent-flaky-tests/6a53c674bda226edb21caefd"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Apex Test Data Factories: Patterns That Prevent Flaky Tests](https://sapotacorpvn.hashnode.dev/apex-test-data-factories-patterns-that-prevent-flaky-tests?utm_source=hashnode&utm_medium=feed)

Every Apex test class needs to create its own data. Done badly, the test setup is duplicated across hundreds of files, breaks when a required field is added, and produces flaky tests that pass in one sandbox and fail in another.

Jul 12 · 7 min read · sapotacorpvn.hashnode.dev  
Read the article

-   [#salesforce](https://hashnode.com/tag/salesforce)
-   [#apex](https://hashnode.com/tag/apex)
-   [#testing](https://hashnode.com/tag/testing)
-   [#test-data](https://hashnode.com/tag/test-data)
-   [#apex-development](https://hashnode.com/tag/apex-development)

## Written by

[SapotaCorp](https://hashnode.com/@sapotacorpvn)

@sapotacorpvn · Hanoi, Vietnam

  
[View profile](https://hashnode.com/@sapotacorpvn)

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
