What is LTS?
Lightning Testing Service or LTS is an unmanaged package developed and released by Salesforce that provides a wrapper for us to integrate client frameworks to be used with lightning components.
Or we can just say that LTS is a set of tools and services that let you create test suites for your lightning components.
Automated tests are the best way to assess the quality of your custom code, and verify that your components work as expected after you write them and continue to work when some changes are made or when something they depend on (the framework, another component, etc) gets updated.
- As we already said, LTS is supported by Jasmine and Mocha which are two of the most popular testing frameworks today
- LTS is able to be used in DX context and non-DX context (we highly recommend that you use it with DX)
One more thing to add that is no really a feature but it is nice to mention, testing Lightning Components with LTS is similar to testing Apex.
If you are familiar with testing Apex, after going through LTS documentation and examples you will for sure be able to test your Lightning Components with LTS.
Best Use Cases?
- When we push apex code from sandbox to prod environment, Salesforce will run all of our tests and code will be deployed only if all tests passed and we have enough code coverage.
We can apply the same concept with LTS, but if you want the full functionality of LTS, you should really try to use it in combination with Salesforce DX (Salesforce Developer Experience).
With Salesforce DX you can run your tests with just one command, and we can use that command with some continuous integration tool (Jenkins, Bamboo, etc), for example, we can run all our test’s whenever we want to make deploy or push which will help us to catch and solve problems early.
How to Install LTS?
There are two ways to install LTS.
One way is with the use of Salesforce DX CLI (LTS works really well in combination with Salesforce DX), but if you are not using Salesforce DX, you can install the LTS package manually just like any other unmanaged package and run your tests in the browser window.
Install LTS with Salesforce DX:
- Install Salesforce CLI and verify the installation
- Verify that the Salesforce DX CLI plug-in is updated
- Install the LTS package with the following command:
After installing LTS, you can run tests with the following command (for Jasmine):
sfdx force:lightning:test:run -a jasmineTest.app
Install LTS unmanaged package manually:
- Log in to your org
- Go to LTS github and click the package installation URL for the latest release
- Authenticate again with the credentials
- Follow the normal package installation prompts. We recommend installing the package for admins only.
- You can also run the test suite from the browser by accessing following URL (for Jasmine):
Base URL is your org’s base URL
In Apex test class if we have some DML statement(insert Contact, delete Case, etc), all these changes will be rolled back after the test is completed.
But if we have some action in our LTS suite and our controller does some DML statement, these statements will not be rolled back at the end of the test, so do not install LTS in Production!
The workaround is to run LTS tests just in your scratch org’s or if you want to create more advanced use cases, you can mock controller actions, which means you won’t do anything on the server-side.
One more thing to be aware of is that LTS does not provide any kind of code coverage metric.
As a conclusion to this post about Lightning Testing Service, we have to say that by starting to use LTS your code quality and stability will greatly improve, which will not only going to have a big impact on your personal development as Salesforce developer but will also have a big positive impact on your clients and your company’s business.
We hope we have been able to introduce you to Lightning Testing Service in Salesforce and that soon, your lightning components will have their test suite.
If you would like to learn more about LTS or share your ideas feel free to contact us.
We would love to hear your thoughts on this topic.