All Projects → rsoesemann → Apex Domainbuilder

rsoesemann / Apex Domainbuilder

Licence: mit
Framework to setup Apex test data in a highly flexible and readable way using the Test Data Builder pattern.

Projects that are alternatives of or similar to Apex Domainbuilder

iOS-Clean-Architecture-Example
An iOS app designed using clean architecture and MVVM.
Stars: ✭ 50 (-18.03%)
Mutual labels:  patterns, clean-code
Apex Unified Logging
Platform-Event-based Apex logger for unified logging over transaction boundaries
Stars: ✭ 101 (+65.57%)
Mutual labels:  apex, clean-code
Guardclauses
A simple package with guard clause extensions.
Stars: ✭ 767 (+1157.38%)
Mutual labels:  patterns, clean-code
codeclimate-apexmetrics
ApexMetrics - Code Climate engine for Salesforce [DISCONTINUED use CC PMD instead)
Stars: ✭ 46 (-24.59%)
Mutual labels:  clean-code, apex
Apex Chainable
Chain Batches in a readable and flexible way without hardcoding the successor.
Stars: ✭ 27 (-55.74%)
Mutual labels:  apex, clean-code
Data Ingestion Platform
Stars: ✭ 39 (-36.07%)
Mutual labels:  apex
Stripeforce
Stripe API Client Library for Force.com
Stars: ✭ 50 (-18.03%)
Mutual labels:  apex
Objectmerge
Open-source solution for merging Salesforce objects and their related objects.
Stars: ✭ 35 (-42.62%)
Mutual labels:  apex
Flutter pokedex
Pokedex app built with Flutter (with lots of animations) using Clean Architecture
Stars: ✭ 972 (+1493.44%)
Mutual labels:  clean-code
React In Patterns Cn
React in patterns 中文版
Stars: ✭ 1,107 (+1714.75%)
Mutual labels:  patterns
Wsdl2apex
Stars: ✭ 54 (-11.48%)
Mutual labels:  apex
Dg Net
Joint Discriminative and Generative Learning for Person Re-identification. CVPR'19 (Oral)
Stars: ✭ 1,042 (+1608.2%)
Mutual labels:  apex
Forcedotcomsprintwall
An agile sprint wall built on the force.com platform with jQuery and Javascript Remoting
Stars: ✭ 42 (-31.15%)
Mutual labels:  apex
Streams
Durable event pipelines.
Stars: ✭ 51 (-16.39%)
Mutual labels:  apex
Forcedotcom Enterprise Architecture
Force.com Enterprise Architecture - First Edition - Source Code
Stars: ✭ 35 (-42.62%)
Mutual labels:  apex
Recapproject
Araç Kiralama Sistemi | Engin Demiroğ
Stars: ✭ 57 (-6.56%)
Mutual labels:  clean-code
Grid
A Lightning Component grid implementation that expects a server-side data store.
Stars: ✭ 35 (-42.62%)
Mutual labels:  apex
Ridge
AWS Lambda HTTP Proxy integration event bridge to Go net/http.
Stars: ✭ 45 (-26.23%)
Mutual labels:  apex
Lc Java
Clean Leetcode solutions in Java
Stars: ✭ 54 (-11.48%)
Mutual labels:  clean-code
Gh Polls
Create a poll with gh-polls
Stars: ✭ 45 (-26.23%)
Mutual labels:  apex

Apex Domain Builder Codacy Badge

Test Data Builder framework to setup test data for complex Apex integration tests in a concise, readable and flexible way.

Deploy to Salesforce

Setting up test data for complex Apex integration tests is not easy, because you need to..:

  • set required fields even if irrelevant for the test
  • insert the objects in the right order
  • create relationships by setting Lookup fields
  • put ugly __c all over the place
  • clutter your code with Map<Id, SObject> to keep track of related records
  • reduce the DML statements to not hit Governor Limits

TestFactories as used by many developers and recommended by Salesforce.com can help to minimize ugly setup code by moving it to seperate classes. But over the time those classes tend to accumulate complexity and redundant spaghetti code.

In the world of Enterprise software outside of Salesforce.com there are experts that have created patterns for flexible and readable (fluent, concise) test data generation. Among them the most notable is Nat Pryce who wrote a great book about testing and somewhat invented the Test Data Builder pattern.

apex-domainbuilder brings those ideas to Apex testing:

  1. By incorporating a simple small Builder class for each test-relevant Domain SObject we centralize all the creation knowledge and eliminating redundancy.
@IsTest
public class Account_t extends DomainBuilder {

	public Account_t() {
		super(Account.SObjectType);

		name('Acme Corp');
	}

	public Account_t name(String value) {
		return (Account_t) set(Account.Name, value);
	}

	public Account_t add(Opportunity_t opp) {
		return (Account_t) opp.setParent(Opportunity.AccountId, this);
	}

	public Account_t add(Contact_t con) {
		return (Account_t) con.setParent(Contact.AccountId, this);
	}
}
  1. By internally leveraging the fflib_SObjectUnitOfWork for the DML all test run dramatically faster.
  2. The Fluent Interface style of the Builder pattern combined with having all the database wiring encapsulated in the Unit of work made each test much more understandable.
    @IsTest
    private static void easyTestDataCreation() {

        // Setup
        Contact_t jack = new Contact_t().first('Jack').last('Harris');

        new Account_t()
                .name('Acme Corp')
                .add( new Opportunity_t()
                                .amount(1000)
                                .closes(2019, 12)
                                .contact(jack))
                .persist();
        
        // Exercise
        ...
	
	
	// Verify
	...
    }
  1. Using Graph algorithms to autodetect the correct insert order in the Unit Of Work.
  2. Is able to handle self-reference fields (e.g. Manager Contact Lookup on Contact) by using a patched fflib Unit of Work.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].