Turn your manual testers into automation experts! Request a DemoStart testRigor Free

Salesforce Testing

Salesforce is a cloud-based customer relationship management (CRM) platform designed to help businesses manage customer interactions and relationships. It provides a suite of tools for managing sales, marketing, customer service, and analytics, all of which are accessible through a web browser or mobile app.

Salesforce is a highly customizable platform that can be tailored to the specific needs of a business. The platform also offers a marketplace of third-party apps and integrations that can extend its functionality and integrate with other business systems. Salesforce is known for its user-friendly interface and its focus on user adoption, which has helped to make it one of the most popular CRM platforms in the world. It is used by businesses of all sizes, from small startups to large enterprises, and across various industries.

Amongst the many products and services that Salesforce offers, here are a few examples of Salesforce products that make development easier:
  • Lightning Platform: Salesforce Lightning is a UI framework and design system allowing developers and administrators to create modern, responsive, and customizable user interfaces for Salesforce applications. In addition to the UI framework and design system, Lightning also includes a range of features and tools for building custom business logic and workflows, such as Lightning Data Service, which provides a standard way to access and manipulate data in Salesforce, and Lightning Flow, which allows developers to create complex, multi-step processes and workflows.
  • Salesforce Mobile SDK: The Salesforce Mobile SDK provides a set of development tools and libraries for building mobile applications that integrate with Salesforce. The Mobile SDK supports both native and hybrid mobile app development and provides features such as offline data access, push notifications, and secure authentication.
  • Heroku: Heroku is a cloud-based application platform that allows developers to build, deploy, and manage applications in a variety of languages, including Java, Ruby, Node.js, and Python. Heroku provides a range of tools and services for building and deploying applications, including a command-line interface, a web-based dashboard, and an add-on marketplace.
  • MuleSoft: MuleSoft is an integration platform that provides a range of tools and services for connecting applications and data sources. MuleSoft provides an Anypoint Platform for building and deploying integrations, as well as a development platform for creating custom connectors and APIs.
  • Tableau: Tableau is a data visualization and business intelligence platform that helps businesses analyze and visualize their data. Tableau provides a range of tools and services for creating custom visualizations, building dashboards, and integrating with other data sources.
  • Einstein: Einstein is a set of AI-powered features and tools that can be integrated with Salesforce products, including Sales Cloud, Service Cloud, and Marketing Cloud. As a developer, you can use Einstein to build custom AI models and integrations that can help automate and optimize various business processes.
  • Salesforce DX: It is a set of tools and features that Salesforce provides to make it easier for developers to build and manage applications on the Salesforce platform. It includes features such as scratch orgs, version control integration, and continuous integration and delivery (CI/CD) pipelines. Salesforce DX is designed to improve the development process and enable developers to work more efficiently.

Salesforce testing can be performed manually or through automated testing tools. Automated testing tools can speed up the testing process, improve accuracy, and reduce the risk of human error. When it comes to backend development and testing, Apex is used which is a strongly typed, object-oriented language that is syntactically similar to Java. For the front end, Salesforce has Lightning frameworks. When it comes to testing, following the testing pyramid is a good idea to ensure maximum coverage and quality.

This means that the following types of testing ought to be done:

Unit Testing

Unit testing is meant to test if each unit of code, like classes, methods, or components, is working as expected. The focus is strictly on the output of the code here. These kinds of tests are run in isolation and hence need to be lightweight. This means that your tests should be such that they operate only on a single unit of code, and if there are mandatory dependencies, then they are mocked.

Depending on your project, you will have to write unit tests for the backend and frontend code. Below are the most commonly used tools to do this.

Backend unit testing

Backend work for Salesforce applications is done using Apex, which is a proprietary language. Thus Salesforce offers certain tools to test this code as well.

Using Apex test execution

Salesforce uses Apex as a programming language to build and customize functionality. It is designed specifically for the Salesforce platform and can be used to create custom business logic, automate processes, integrate with external systems, and create custom user interfaces. Developers can use Apex to write triggers, which execute custom code before or after data manipulation events such as inserts, updates, or deletions. Apex can also be used to create Visualforce pages, which are custom user interfaces that interact with data on the Salesforce platform. Additionally, Apex can be used to build custom integrations with external systems and to create complex workflows and approval processes.

In Salesforce, the @isTest annotation is used to mark a class or method as a test class or test method. Test classes and methods are used for unit testing, which is the process of testing individual pieces of code to ensure that they work correctly and meet the specified requirements. You can execute your tests using the following:
  • Apex Test Execution page: This feature in the Salesforce UI allows developers to run Apex tests asynchronously and view the test results. Developers can use filters to view test results by class, method, outcome, and more.
  • Developer Console: The Developer Console is a tool within Salesforce that provides a range of features for developers, including the ability to create and run tests, execute anonymous Apex code, and debug code.
  • Using the API: You can use the runTests() call to run tests synchronously. Based on what you specify in the RunTestsRequest object, this single call allows you to execute tests in a specific namespace, tests in a specific subset of classes in a specific namespace, or tests in all classes. You can also choose to run your tests synchronously or asynchronously.
  • Using ApexTestQueueItem: You can use the ApexTestQueueItem to run your tests asynchronously. The tests get added to a job queue, and the results become available once the execution is done. Since this process makes use of the Apex scheduler, you can schedule your tests to run at specific times.

Here is an example of a unit test written in Apex language for testing the functionality of the MileageTracker application. It consists of two test methods – runPositiveTestCases() and runNegativeTestCases().

The runPositiveTestCases() method tests the positive scenarios of the application. It creates test data for two users, inserts test mileage records for them, and verifies if the total mileage is calculated correctly. It also tests the bulk insertion of mileage records and ensures that the daily limit of 500 miles is not exceeded.

The runNegativeTestCases() method tests the negative scenario of the application where a mileage record with more than 500 miles is inserted. It verifies if the custom validation rule is working as expected by catching the DMLException and checking its properties like status code, fields, and error message.

private class MileageTrackerTestSuite {
  static void setup() {
    List<User> users = new List<User> {
      new User(Alias = 'auser', Username = '[email protected]', Email = '[email protected]', EmailEncodingKey = 'UTF-8', LastName = 'Testing', LanguageLocaleKey = 'en_US', LocaleSidKey = 'en_US', ProfileId = [SELECT Id FROM Profile WHERE Name='Standard User' LIMIT 1].Id, TimeZoneSidKey = 'America/Los_Angeles'),
      new User(Alias = 'tuser', Username = '[email protected]', Email = '[email protected]', EmailEncodingKey = 'UTF-8', LastName = 'Testing', LanguageLocaleKey = 'en_US', LocaleSidKey = 'en_US', ProfileId = [SELECT Id FROM Profile WHERE Name='Standard User' LIMIT 1].Id, TimeZoneSidKey = 'America/Los_Angeles')
    insert users;
  static testMethod void runPositiveTestCases() {
    Double totalMiles = 0;
    final Double maxTotalMiles = 500;
    final Double singleTotalMiles = 300;
    final Double u2Miles = 100;
    User u1 = [SELECT Id FROM User WHERE Alias='auser' LIMIT 1];
    System.RunAs(u1) {
      Mileage__c testMiles1 = new Mileage__c(Miles__c = singleTotalMiles, Date__c = System.today());
      insert testMiles1;
      totalMiles = getMilesForUser(u1.Id);
      Assert.areEqual(singleTotalMiles, totalMiles);
      List<Mileage__c> testMiles2 = new List<Mileage__c>();
      for(integer i=0; i<200; i++) {
        testMiles2.add( new Mileage__c(Miles__c = 1, Date__c = System.today()) );
      insert testMiles2;
      totalMiles = getMilesForUser(u1.Id);
      Assert.areEqual(maxTotalMiles, totalMiles);
    User u2 = [SELECT Id FROM User WHERE Alias='tuser' LIMIT 1];
    System.RunAs(u2) {
      Mileage__c testMiles3 = new Mileage__c(Miles__c = u2Miles, Date__c = System.today());
      insert testMiles3;
      totalMiles = getMilesForUser(u2.Id);
      Assert.areEqual(u2Miles, totalMiles);
  static testMethod void runNegativeTestCases() {
    User u3 = [SELECT Id FROM User WHERE Alias='tuser' LIMIT 1];
    System.RunAs(u3) {
      Mileage__c testMiles3 = new Mileage__c(Miles__c = 501, Date__c = System.today());
      try {
        insert testMiles3;
        Assert.fail('DmlException expected');
      } catch (DmlException e) {
        Assert.areEqual('FIELD_CUSTOM_VALIDATION_EXCEPTION', e.getDmlStatusCode(0));
        Assert.areEqual(Mileage__c.Miles__c, e.getDmlFields(0)[0]);
        Assert.isTrue(e.getMessage().contains('Mileage request exceeds daily limit(500): [Miles__c]'), 'DMLException did not contain expected validation message:' + e.getMessage());
  private static Double getMilesForUser(Id userId) {
    Double totalMiles = 0;
    for(Mileage__c m:[SELECT miles__c FROM Mileage__c WHERE CreatedDate = TODAY AND CreatedById = :userId AND miles__c != null]) {
      totalMiles += m.miles__c;
    return totalMiles;

Frontend unit testing

Javascript is typically used when it comes to frontend. Instead of reinventing the wheel, Javascript testing tools like Mocha, Jest, and Jasmine are available with wrappers. Let’s take a look at these testing alternatives.

Lightning Testing Service (LTS)

Lightning Testing Service (LTS) is a Salesforce tool that acts as a bridge between JavaScript testing tools and the Salesforce platform. It provides a way to test the Lightning components and applications developed using the Salesforce Lightning web components framework.

LTS runs the tests in a headless browser environment and provides support for testing frameworks such as Jest, Mocha, and Jasmine. It enables developers to write unit tests, integration tests, and end-to-end tests for their Lightning components and applications.

Using Jasmine

Jasmine is a behavior-driven development (BDD) framework for testing JavaScript code. These tests are organized into “specs,” which define what is being tested and include one or more “expectations” that describe what the code under test should do. Jasmine provides a number of matchers that can be used in expectations to check that values are what they should be, such as toEqual, toBe, toContain, toBeGreaterThan, and many others.

It also provides a number of utility functions for setting up tests, such as beforeEach, afterEach, beforeAll, and afterAll, which allow you to define setup and teardown code that will run before or after each spec or suite of specs. This can be useful for initializing test data, cleaning up after tests, or setting up dependencies that are shared across multiple specs.

Here is a simple test using Jasmine. The afterEach function is called after each test, and its purpose is to clear the rendered test components from the DOM. The test is for the c:egRenderElement component, and it checks if the expected content has been added to the DOM.

describe("Lightning Component Testing Examples", function(){
  afterEach(function() {
    describe('c:egRenderElement', function(){
      it('renders specific static text', function(done) {
        $T.createComponent("c:egRenderElement", {}, true)
          .then(function(component) {
            expect(document.getElementById("content").textContent).toContain("Hello World!");
    }).catch(function(e) {

Using Jest

Salesforce supports Jest as the preferred testing framework for Lightning Web Components (LWC). Jest is a popular JavaScript testing framework that allows developers to write unit tests and integration tests for LWCs.

Mentioned below is a Jest test file for a Salesforce Lightning web component called “c-hello”. The file is named “hello.test.js” and is written in JavaScript. The import statement is used to import two functions from the Lightning Web Components framework: createElement and Hello. createElement is used to create the c-hello component, while Hello is used as the reference to the c-hello component’s JavaScript class.

The describe function is used to group related test cases together. In this case, all of the tests will be related to the “c-hello” component. The afterEach function is called after each test case in the “c-hello” group has run. It removes all child elements from the document.body element to ensure that the DOM is in a clean state before each test case. The it function defines a single test case. In this case, the test is verifying that the component displays the greeting “Hello, World!”.

Within the test case, the createElement function is used to create a new instance of the c-hello component. The is option specifies the class to use as the component’s implementation. The newly created component is then added to the document.body. The querySelector function is used to retrieve the div element within the component’s shadow root. The expect function is then used to verify that the text content of the div element is “Hello, World!”.

// hello.test.js
import { createElement } from 'lwc';
import Hello from 'c/hello';

describe('c-hello', () => {
  afterEach(() => {

    // The jsdom instance is shared across test cases in a single file so reset the DOM
    while (document.body.firstChild) {
  it('displays greeting', () => {

    // Create element
    const element = createElement('c-hello', {
      is: Hello

    // Verify displayed greeting
    const div = element.shadowRoot.querySelector('div');
    expect(div.textContent).toBe('Hello, World!');

Using Mocha and Chai

Mocha is a JavaScript testing framework that provides a flexible and straightforward way to write tests. It allows you to write tests using a variety of testing styles, including BDD (Behavior-Driven Development), TDD (Test-Driven Development), and traditional functional testing. Mocha provides a simple and flexible API for defining and running tests, with support for asynchronous testing and hooks for handling pre- and post-test actions.

Chai, on the other hand, is an assertion library for JavaScript that can be used with any testing framework, like Mocha. It provides a range of built-in assertions for testing common things like equality, type, and presence, as well as support for custom assertions. Chai’s flexible API also allows for various testing styles, including BDD-style assertions using natural language constructs like “should” and “expect”.

Together, Mocha and Chai provide a powerful and flexible testing solution for JavaScript applications. Mocha provides the framework for organizing and running tests, while Chai provides the syntax for writing assertions within those tests.

Integration Testing

Integration tests form the next layer of control after unit testing. They are not as many as unit tests since their purpose is to verify if module integrations are working properly. The goal of integration testing is to verify that the different components of the system work together as expected and that data is accurately passed between the different components. This could be integrations between different components, classes, controllers, network systems, and databases. Integration testing can be used to test the integration between different Salesforce components, such as custom code, workflows, triggers, and external systems.

Integration testing should be done in Salesforce whenever you are building an application that involves integrating with other systems or external services. You can use the same tools as above for backend and frontend test writing and execution. Here are some examples of scenarios where integration testing is typically needed:
  • Integrating with third-party APIs: If you are building an application that integrates with third-party APIs, such as payment gateways, email providers, or social media platforms, you need to perform integration testing to ensure that data is being exchanged correctly and that the application is behaving as expected.
  • Custom integrations: If you are building custom integrations between Salesforce and other systems, such as an ERP or a marketing automation platform, you need to perform integration testing to ensure that data is being exchanged correctly and that the integration is working as expected.
  • Upgrading Salesforce: If you are upgrading your Salesforce instance to a new version or adding new features, you need to perform integration testing to ensure that the changes don’t impact any of the existing integrations.
  • Changes to integrations: If you are making changes to any of the existing integrations, such as adding new fields or updating workflows, you need to perform integration testing to ensure that the changes don’t cause any issues.
  • Data migration: If you are migrating data from another system to Salesforce, you need to perform integration testing to ensure that the data is being migrated correctly and that the new data is compatible with the existing data in Salesforce.

End-to-End Testing

Testing an application end-to-end means checking if the scenarios that an end user would perform are working correctly. In the case of unit and integration testing, we focused on just whether the code gave the desired output. However, over here, the entire system is seen as a whole, rather than bits and pieces of code. Your end-to-end tests might range across applications in case of checking scenarios using Salesforce integrations.

Let us look at some of the tools we can use for this form of testing.
  • Provar
  • Selenium
  • testRigor

When it comes to testing Salesforce, it is important to remember that there are specific security features and restrictions that may affect the use of end-to-end testing tools. Working closely with your Salesforce administrator and following best practices for testing in Salesforce will help get you good test coverage.

Using Provar

Provar is a test automation tool that is designed to help users automate end-to-end tests for Salesforce applications. It provides a no-code, drag-and-drop interface for building automated tests that can be used to verify the functionality of Salesforce applications across different environments and scenarios.

Provar is built on top of the Salesforce platform and can be integrated with various Salesforce tools and services, including Sales Cloud, Service Cloud, and Marketing Cloud. It supports both manual and automated testing and provides a centralized platform for managing test cases, test data, and test results.

Though they do support testing of other major products besides Salesforce, Provar may not be suitable for very complex test scenarios that require a high degree of customization or integration with other tools. It may not be able to automate certain types of applications or environments, and it may require additional configuration or customization to work with certain technologies or frameworks. Additionally, Provar may require specialized knowledge or training to use effectively, particularly for non-Salesforce applications.

Using Selenium

Selenium is an open-source, cross-platform automation testing tool that is a popular choice for browser testing. It provides a way to automate the testing of web applications, including Salesforce applications. Selenium allows users to write test scripts in various programming languages such as Java, Python, C#, etc., and run them against web browsers. It supports multiple browsers, including Google Chrome, Firefox, Safari, and Internet Explorer. Selenium provides a suite of tools for web testing, including Selenium IDE (Integrated Development Environment), Selenium WebDriver, and Selenium Grid. These tools can be used together or separately to automate web testing tasks.

Using testRigor

A part of the Salesforce App Exchange, testRigor is specifically designed to streamline end-to-end testing automation. Its distinctive feature lies in its ability to transform plain English language instructions into tests, simplifying the test creation process and encouraging user-friendly interactions.

Uniquely, testRigor’s intelligent engine negates the need to write Xpaths for UI element identification. Instead, users can specify relative locations, a feature that promotes test stability, even when UI element locators undergo minor changes. Additionally, testRigor includes a record and playback extension, allowing users to record browser interactions and automatically generate executable scripts in plain English.

Beyond these core features, testRigor offers a wealth of capabilities. It supports the establishment of reusable rules, reducing redundancy in commands. Its capacities extend to table data testing, data copying and pasting, test data generation, audio testing, file downloads and uploads, and input value typing.

What’s more, testRigor is compatible with a variety of platforms, including web, mobile, and desktop, and can operate across different devices. It also integrates seamlessly with other infrastructure providers, CI/CD frameworks, and test case management tools, offering users an all-in-one testing solution.

Here’s an illustrative example of a testRigor mobile app test case, demonstrating the tool’s easy-to-use approach to test writing:
upload file from saved value "Profile_photo" to mobile device
AppLogin // pre-defined rule to perform login
press "Profile" 
press "Get Started" if present
check that page contains "Years of Experience"
click "close" in the context of "complete your profile" if present
click "Camera"
click "Photo albums"
click middle of screen
check that page contains "Years of Experience"
click "Done" at the bottom 
click on image from stored value "Profile_photo" with less than "10" % discrepancy
click "Add Bio"
enter stored value "Bio" into "Enter your bio here"
click "Save"
check that "Bio is too long!" color is "ff0000"


The process of testing is vital for building dependable and strong applications on the Salesforce platform. This testing can take several forms, including unit testing, integration testing, and end-to-end testing, each playing a distinct role in guaranteeing the quality of the application. The choice of the right testing tool should take into account the specific needs of the testing scenario and the capabilities offered by a specific tool.

Join the next wave of functional testing now.
A testRigor specialist will walk you through our platform with a custom demo.
Related Articles

Infor Testing

Infor ERP is a comprehensive software solution designed to help organizations efficiently manage and streamline their business ...

Oracle ERP Testing

One of the global leaders in the industry, Oracle provides ERP solutions comprising a suite of integrated software applications. ...

Vista by Viewpoint Testing

Experience an all-inclusive construction accounting and operations solution that offers unmatched customizability, scalability, ...