All Projects → jamessimone → apex-dml-mocking

jamessimone / apex-dml-mocking

Licence: MIT license
DML mocking, CRUD mocking, dependency injection framework for Salesforce.com (SFDC) using Apex

Programming Languages

Apex
172 projects
powershell
5483 projects

Projects that are alternatives of or similar to apex-dml-mocking

apex-mocks-stress-test
Testing out FFLib versus Crud / CrudMock
Stars: ✭ 47 (+23.68%)
Mutual labels:  salesforce, apex, sfdc, salesforce-developers, apex-framework, apex-test, salesforce-apex, apex-class
apexmock
force.com Mock data and fixtures for Apex Unit Tests
Stars: ✭ 24 (-36.84%)
Mutual labels:  salesforce, apex, sfdc, salesforce-developers, apex-framework, salesforce-apex
NebulaFramework
A development framework for Salesforce's Apex language & the Force.com platform
Stars: ✭ 28 (-26.32%)
Mutual labels:  salesforce, apex, sfdc, salesforce-developers, apex-framework, salesforce-apex
apex-fp
Functional programming for Salesforce Apex
Stars: ✭ 231 (+507.89%)
Mutual labels:  salesforce, apex, salesforce-developers, salesforcedx
apex-tmLanguage
Salesforce Apex Language syntax grammar used for colorization
Stars: ✭ 27 (-28.95%)
Mutual labels:  salesforce, apex, salesforce-developers, salesforcedx
Apex-Code-Conventions
Apex conventions and best practices for Salesforce Developers
Stars: ✭ 28 (-26.32%)
Mutual labels:  salesforce, apex, salesforce-developers, salesforcedx
texei-sfdx-plugin
Texeï's plugin for sfdx
Stars: ✭ 99 (+160.53%)
Mutual labels:  salesforce, salesforce-developers, salesforcedx
apex-rollup
Fast, configurable, elastically scaling custom rollup solution. Apex Invocable action, one-liner Apex trigger/CMDT-driven logic, and scheduled Apex-ready.
Stars: ✭ 133 (+250%)
Mutual labels:  salesforce, apex, salesforce-developers
sf-cross-cutting-concerns
Apex Cross cutting concerns for Salesforce
Stars: ✭ 29 (-23.68%)
Mutual labels:  salesforce, apex, apex-framework
HTTPCalloutFramework
HTTP Callout Framework - A light weight callout framework for apex HTTP callouts in Salesforce
Stars: ✭ 43 (+13.16%)
Mutual labels:  salesforce, salesforce-developers, salesforce-apex
apex-utils
Utility classes for Salesforce Apex development
Stars: ✭ 20 (-47.37%)
Mutual labels:  salesforce, apex, salesforce-developers
apex-rest-route
A simple framework for building Restful API on Salesforce
Stars: ✭ 75 (+97.37%)
Mutual labels:  salesforce, apex, apex-framework
universalmock
A universal mock class in Apex
Stars: ✭ 55 (+44.74%)
Mutual labels:  salesforce, apex, apex-test
APEX-Q
A promise library for Salesforce
Stars: ✭ 30 (-21.05%)
Mutual labels:  salesforce, apex, apex-framework
R.apex
Functional utility library for Apex
Stars: ✭ 80 (+110.53%)
Mutual labels:  salesforce, apex, salesforce-developers
Script.apex
Evaluate Javascript expressions in Apex
Stars: ✭ 18 (-52.63%)
Mutual labels:  salesforce, apex, salesforce-developers
Soqlx
SoqlXplorer is an awesome tool for developers using the Salesforce.com platform.
Stars: ✭ 220 (+478.95%)
Mutual labels:  salesforce, apex
Sfdx Mass Action Scheduler
🚀 Declaratively schedule Process Builder, Flows, Quick Actions, Email Alerts, Workflow Rules, or Apex to process records from Reports, List Views, SOQL, or Apex.
Stars: ✭ 200 (+426.32%)
Mutual labels:  salesforce, apex
codeclimate-apexmetrics
ApexMetrics - Code Climate engine for Salesforce [DISCONTINUED use CC PMD instead)
Stars: ✭ 46 (+21.05%)
Mutual labels:  salesforce, apex
spaghetti-cmd-loader
Salesforce Custom Metadata Type Loader, designed for Lightning Experience
Stars: ✭ 13 (-65.79%)
Mutual labels:  salesforce, salesforce-developers

Apex DML Mocking

Welcome to the SFDX project home for blazing fast Apex unit tests! For your consideration, this is an example of how to implement the full CRUD (Create Read Update Delete) mocking implementation within your own Salesforce orgs. You can find out more information by perusing:

  • force-app for implementation details
  • example-app for an example Account Handler with mocking set up

Writing tests that scale as the size of your organization grows is an increasingly challenging problem in the Salesforce world. It's not uncommon in large companies for deploys to last several hours; the vast majority of that time is spent running tests to verify that your code coverage is good enough for the deploy to succeed. Tests don't need to take that long.

This repo shows you how you can mock your SOQL queries and DML statements in Apex by using lightweight wrappers that are dependency injected into your business logic objects. This allows you to replace expensive test setup and test teardown with a fake database. I've used this method to cut testing time down by 90%+ -- in a small org, with only a few hundred tests, running tests and deploying can be done in under five minutes (easily). In large orgs, with many hundreds or thousands of tests, overall testing time tends to scale more linearly with organizational complexity; there are additional optimizations that can be done in these orgs to keep deploys in the 10-15 minutes range.

DML Mocking Basics

Try checking out the source code for the DML wrapping classes:

SOQL Mocking Basics

Take a look at the following classes to understand how you can replace raw SOQL in your code with testable (and extendable) strongly typed queries:

Then, move on to the more complicated examples:

While opinionated in implementation, these classes are also just scratching the surface of what's possible when taking advantage of the Factory pattern in combination with the Repository pattern, including full support for:

  • strongly typed subqueries (queries returning children records)
  • strongly typed parent-level fields
  • the ability to easily extend classes like Repository to include things like limits, order bys, etc ...

Dependency Injection Basics

The "Factory" pattern is of particular importance for DML mocking, because it allows you to have only one stub in your code for deciding whether or not to use mocks when running tests; crucially, the stub is only available when tests are being run: you cannot mock things in production-grade code.

You can have as many Factories as you'd like. I like to break my Factories out by responsibility:

  • A factory for Trigger handlers
  • A factory for basic classes
  • The RepoFactory for CRUD related objects

It's a pretty standard approach. You might choose to break things down by (business) domain. There's no right way.


More Information

For more information on these patterns and how to use them, consider the free resources I've published under The Joys Of Apex. Thanks for your time!

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].