Newer Version Available

This content describes an older version of this product. View Latest

How Lightning Testing Service Works

LTS simplifies building test suites, and is fully integrated with Salesforce DX.

LTS consists of two major components:

  • The LTS unmanaged package, listed by release version on the project Releases page
  • The LTS install command for the Salesforce CLI
The unmanaged package includes LTS infrastructure, including a test runner app, and some example tests. Once the package is installed in your org, you can run the example tests by going to the following URL:
1yourInstance/c/jasmineTests.app

When you run tests manually in a browser, you’re using only the pieces of LTS provided in the package.

LTS metadata and runtime flowcharts

For more sophisticated development processes, use the LTS commands included with the Salesforce DX CLI plugin. The Salesforce CLI allows you to integrate LTS into your automated testing, continuous integration, and other source-based development processes.

The command line tool automates running your test suites. It opens the same URL you can open manually, and uses WebDriver to observe the test suite as it runs. Then it parses and packages the results for use in command line-based development processes.

Installing LTS is a one line command in the Salesforce DX CLI. Once installed, you can work with your test suite in various ways from the command line.

If you just want to “kick the tires,” that's cool, too. You can manually install the LTS unmanaged package. The package provides the test service app and an example test suite. It also includes example components that the test suite runs against. You run the test suite by accessing the URL for the LTS app in your org.

Note

Write your tests using a JavaScript testing framework of your choosing. We provide easy-to-use wrappers for Jasmine and Mocha.

A simple Jasmine test spec looks like the following:

1/** 
2 * This is a 'hello world' Jasmine test spec
3 */
4describe("A simple passing test", function() {
5    it("checks that true is always true", function() {
6        expect(true).toBe(true);
7    });
8});

A Mocha test looks similar.

1/** 
2 * This is a 'hello world' Mocha test
3 */
4var assert = require('assert');
5    describe('A simple passing test', function() {
6        it('checks that true is always true', function() {
7            assert.equal(true, true);
8        });
9    });

You can write your own wrapper if you prefer a different testing framework. It's not hard, but plan on half a day to a day of work.

LTS also provides utilities specific to the Lightning Component framework, which let you test behavior specific to Lightning components. Details are explained in comments in the example tests.

Your test suite is deployed in the form of an archive (zip) static resource. Once LTS is installed and configured, you make changes to your test suite, create the archive, and upload it to your org. Once uploaded you can run the test suite via the command line or via URL.

Don't run tests in your production org. LTS doesn't provide an isolated test context or transaction wrapper. DML operations you perform in your tests won't be rolled back at the end of the test. We recommend that you run your LTS test suites only in scratch orgs, using data provided by the test suite itself.

Warning