Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jongpie/smarttestdatafactory
A lightweight library for dynamically generating Sobject records & setting any required fields, based on the field's metadata
https://github.com/jongpie/smarttestdatafactory
apex apex-test apex-test-data-factory
Last synced: 19 days ago
JSON representation
A lightweight library for dynamically generating Sobject records & setting any required fields, based on the field's metadata
- Host: GitHub
- URL: https://github.com/jongpie/smarttestdatafactory
- Owner: jongpie
- License: mit
- Created: 2018-03-18T18:14:12.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-28T02:19:15.000Z (almost 6 years ago)
- Last Synced: 2024-10-24T03:29:20.682Z (2 months ago)
- Topics: apex, apex-test, apex-test-data-factory
- Language: Apex
- Homepage:
- Size: 11.7 KB
- Stars: 20
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Smart Test Data Factory
An Apex library for dynamically setting any required fields on an Sobject record, based on the field's metadata
## Overview
This library simplifies the process of creating of test records in Salesforce. It can be leveraged in Apex unit tests to automatically set field values for any required field. This is useful when you need to insert records but the exact field values are not relevant to your tests.> **Note**: Lookup & master-detail fields are **not** set by this library - you must set these fields yourself before you insert your record.
## Usage
1. **Create your Sobject** You can provide an empty record (`new Account()`), or you can set your own values for any field values that are important to your tests (`new Account(Type='Prospect')`).
2. **Create a new instance of TestDataFactory by passing your record in the constructor** When you're ready, call populateRequiredFields() to set values for any null required fields.```
Account testAccount = new Account();
new TestDataFactory(testAccount).populateRequiredFields();
System.assertNotEquals(null, testAccount.Name);
insert testAccount;
```