wes1278 / Salesforce-Test-Factory

SObject factory that can be used in unit tests to create test data.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Salesforce-Test-Factory

SObject factory that can be used in unit tests to create test data.

Deploy to Salesforce

Usage:

// The TestFactory will pre-fill all the fields we typically need
Account a = (Account)TestFactory.createSObject(new Account());
insert a;

// You can also set values to be used. Any values set in the constructor will override the defaults
Opportunity o = (Opportunity)TestFactory.createSObject(new Opportunity(AccountId = a.Id));

// You can also specify a specific set of overrides for different scenarios
Account a = (Account)TestFactory.createSObject(new Account(), 'TestFactory.AccountDefaults');

// Finally, get a bunch of records for testing bulk
Account acc = new Account(Name = 'Names rock',BillingStreet = 'street',BillingState='state',BillingCity='city',BillingPostalCode='12345');
Account[] accounts = (Account[])TestFactory.createNsObjects(acc,15);
insert accounts;

About

SObject factory that can be used in unit tests to create test data.

License:MIT License


Languages

Language:Apex 100.0%