Skip to content

Mock Data Layer Pattern - Learn how to use dependency injection to create a Data Layer that will allow you to improve your Apex tests performance with mock data relationships.

Notifications You must be signed in to change notification settings

gitmatheus/Mock-Data-Layer-Pattern

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Mock Data Layer Pattern

Presented by Matheus Gonçalves

Mock Data Layer

Originally presented at Salesforce Developer Group, Tampa, United States.


Files used in this exploratory presentation:

force-app
    main
        default
            classes
                ◦ AccountTriggerHandler.cls
                ◦ DataLayerHandler.cls
                ◦ DocumentHelper.cls
                ◦ DocumentHelperTest.cls
                ◦ DocumentHelperWithDataLayer
                ◦ DocumentHelperWithDataLayerTest
                ◦ TestDataFactory.cls
                ◦ TestUtils.cls
            triggers
                ◦ AccountTrigger.trigger

Apex tests are essential to the overall health of your Salesforce org. The Apex testing framework enables you to write and execute tests for your Apex classes and triggers on the Lightning Platform. Apex unit tests ensure high quality for your Apex code and let you meet the requirements for deploying Apex.

It's very common to have a Test Factory for your Apex tests, creating several records, which is absolutely needed especially when testing bulk processing operations.

However, besides bulk testing, you may want to test a singular method from a Helper class or run your tests with fake data. Here, instead of inserting real records in your Salesforce org, you can use the Data Layer pattern, and implement an interface that will allow you to run tests with mock data, which makes your tests run a lot faster.

You can mock virtually any relationship if you use a Mock Data Layer Pattern, by adding an Interface to your Helper class. Let’s call it IDataLayer.

Add this new Interface to the Helper class (here, called DocumentHelperDataLayer.cls).

More details at matheus.dev.


About

Mock Data Layer Pattern - Learn how to use dependency injection to create a Data Layer that will allow you to improve your Apex tests performance with mock data relationships.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages