ABSYZ ABSYZ

  • Home

    Home

  • About us

    Who We Are

  • Our Expertise

    What we Do

  • Our Approach

    How We Do It

  • Products

    What We Made

  • Industries

    Who We Do It For

  • Clients

    Whom We Did It For.

  • Article & Blogs

    What Experts Think

  • Careers

    Join The Team

  • Get In Touch

    Let’s Get Started

ABSYZ

Lightning Testing Service

Home / Article & Blogs / Salesforce / Lightning / Lightning Testing Service
By Mahalakshmi Sadhananthan inLightning, Lightning Testing Service

As the size of complexity of Lightning Apps grew bigger, we could try to maintain the code quality of our Lightning Component like the same way we maintain in Apex. So the first thing we must start to look at was, what Salesforce provides out of the box for us to gauge the quality, the sad thing is we have “Apex testing frameworks” for testing code coverage of Apex, but there is nothing for lightning right now. So obviously the next thing for us to look at was what tools available outside Salesforce, that developers are already using right now.

Luckily there are lot of tools already available with other Client testing frameworks. Couple of libraries like Jasmine, Mocha are available but the problem is these libraries don’t exactly work out of Lightning Component because lightning works on Aura framework.

What is Lightning Testing Service?

Lightning Testing Service(LTS) is “Managed Package” developed and released by Salesforce which provides wrapper for us to integrated existing client frameworks to be used with lightning component.

What is Wrapper?

LTS doesn’t aim to reinvent the wheel and provide us with a whole new way of testing Javascript. All LTS aims to do is to provide the resource for us to be able to use what developers are already using as  “Industry standards” that salesforce provides.

Some Key features:

  • LTS is supported with Jasmine and Mocha which are the two most popular client side testing frameworks today.

  • LTS is able to be used with Salesforce DX and as well as in non Salesforce DX context.

Now Lets see End – to – End flow of how we can use Lightning Component Service:

  1. Create your Lightning Component.
  2. Install LTS.
  3. Write a Javascript test suite.
  4. Create a Test Runner app.
  5. Run your Tests.

Create your Lightning Component

  1. In the Developer Console, click File > New > Lightning Component. Specify QuickContacts as the bundle name and click Submit
  2. Implement the component as follows:

<aura:component implements=”force:appHostable”>

<p>ContactList goes here</p>

</aura:component>

3. The component implements the force:appHostable interface to indicate that it can run in the Salesforce1 applicationLightning components can include other Lightning components and regular HTML marku

4. Click File > Save to save the file

Install Lightning Testing Service

Its time to Install LTS into our Org. LTS can be used with Salesforce DX context and as well as non Salesforce DX context. Testing Lightning component with LTS and testing apex is quite similar.There are two ways you can install the LTS. The simplest is to use the Salesforce DX CLI. If you’re not using Salesforce DX, you can manually install the unmanaged package.

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

A simple Jasmine test spec looks like the following:

/*** This is a ‘hello world’ Jasmine test spec*/

describe(“A simple passing test”, function() {

    it(“checks that true is always true”, function() {

        expect(true).toBe(true);

    });

});

A similar Mocha test looks, well, similar:

/*** This is a ‘hello world’ Mocha test */

var assert = require(‘assert’);

describe(‘Test the nature of truth’, function() {

    describe(‘A simple passing test’, function() {

        it(‘checks that true is always true’, function() {

            assert.equal(true, true);

        });

    });

});

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.

The LTS also provides utilities specific to the Lightning Component framework, which let you test behavior specific to Aura components. Your test suite is deployed in the form of an archive (zip) static resource. Once the 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.

1.If your using LTS with Salesforce DX

Salesforce DX includes a one line command for automatically installing the LTS unmanaged package. Once installed, you can work with your test suite in a variety of ways from the command line. This approach also facilitates systematic automated testing.The Salesforce DX CLI also allows you to use the sfdx command line tool to perform automated testing as part of your development process, including automated process, such as continuous integration.

  • For installing Salesforce DX CLI follow the instructions given below for your operating system :
  • Install the Salesforce DX CLI in the Salesforce DX Setup Guide
  • Verify that the Salesforce DX CLI plug-in is installed and updated by running the following command in your shell or terminal application:

→ sfdx update

Additional verification details are available in Verify Your Installation and Install the Plug-In in the Salesforce DX Setup Guide.

  • Install the LTS package with the following command:

          → sfdx force:lightning:test:install

This installs the latest version of the LTS package into your default SFDX org. See the        help for the install command for additional options.

After you install LTS with Salesforce DX, you can run your tests from the command line using the sfdx tool. For example:

→ sfdx force:auth:web:login -s     # connect to your scratch org

→ sfdx force:source:push           # push local source to the scratch org

→ sfdx force:lightning:test:run -a jasmineTests.app   # run the test suite

When you run the

→ force:lightning:test:run -a jasmineTests.app

command in a connected workspace you should see something like the following:

This tells you that the command line tools are working, and connected to your development org.

      2. If your not using Salesforce DX

If you’re not using Salesforce DX, you’re missing out a lot, but you can still use LTS.      Installing the LTS package is just like installing any other unmanaged package.

  • Log in to your org. We recommend that you create a new DE org for evaluating the LTS.
  • Go to the project Releases page, and click the package installation URL for the latest release.
  • Authenticate again with the credentials for your DE org.
  • Follow the normal package installation prompts. We recommend installing the package for admins only.

          However you install it, the LTS package includes the following items:

Example test suites

  • Jasmine JavaScript files in archive static resources
  • Mocha JavaScript files in archive static resources
  • Example components to be tested
    • Components, an Apex class, and a custom label
  • LTS infrastructure
    • Jasmine framework and wrapper
    • Mocha framework and wrapper
    • LTS test utilities
    • Test runner component
    • Wrapper test app

Once installed, you can run the example test suite by going to the following URL in your org:

→  https://<myServer>/c/jasmineTests.app (Jasmine)

→ https://<myServer>/c/mochaTests.app (Mocha)

This page tells you that the package is correctly installed and LTS is working in your org.

Write a Javascript test suite
Components for Testing

The components provided in the package can be accessed as you would any Aura component.

  • In the Developer Console
  • In the Force.com IDE, in the /aura/ directory
  • By converting your org’s metadata into a format that you can work with locally, using Salesforce DX

You can also explore the components directly from the repo. They’re available in the lightning-component-tests/main/default/aura directory.

There are more than a dozen different components, designed to be used in illustrative tests. Each of the components has a description of its behavior in its “.auradoc” documentation file.

Test Suites

The example tests are included in the form of static resources. There are four test suites included in the LTS package, three for Jasmine and one for Mocha:

  • jasmineHelloWorldTests.resource — A very simple Jasmine example including one passing and one failing test.
  • jasmineExampleTests.resource — The main Jasmine example test suite.
  • jasmineLightningDataServiceTests.resource — Some Jasmine examples specific to testing Lightning Data Service-based components.
  • mochaExampleTests.resource — The Mocha example test suite, which provides examples parallel to the main Jasmine test suite.

The remainder of the static resources are infrastructure used by the LTS. They’re briefly described in Use Another JavaScript Test Framework.The jasmineExampleTests.resource and mochaExampleTests.resource files are each a single JavaScript file containing a complete test suite. It’s a single file for convenience in delivery and exploration. Your own test suites can include many such files. The test suites are copiously commented. The code and comments serve as the official documentation for how to write tests.

Run Your Tests

And the final step is to run our tests,

  1. If your not using DX, we just have to push that to whatever source we want and navigate to actual Aura application and it will run all our tests in a nice UI.
  2. If your using DX its even simpler because we can utilize our CLI command

→ sfdx fore:lightning:test:run

In order to get all the coverage.

Benefits:

  • It increase the code quality which helps to build Customer Trust.
  • It helps in catching problems at the very early stage of development which in turn helps in saving time and money.

Points to Remember:

  • Don’t run tests in your production org. The 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.
  • Second thing is LTS does not provide any kind of Code Coverage and Matrics.

 

SalesforceSFDC
80
Like this post
2 Posts
Mahalakshmi Sadhananthan

Search Posts

Archives

Categories

Recent posts

BioAsia 2023 in Hyderabad: An Annual International Event

BioAsia 2023 in Hyderabad: An Annual International Event

The Role Of Marketing in Small & Medium Enterprises

The Role Of Marketing in Small & Medium Enterprises

Salesforce For Retail: How Salesforce CRM Can Help Retailers

Salesforce For Retail: How Salesforce CRM Can Help Retailers

What is ChatGPT & How Does It Work?

What is ChatGPT & How Does It Work?

What Is Graphic Design? (Executive Summary 2023)

What Is Graphic Design? (Executive Summary 2023)

  • Previous PostChange Data Capture Events in Salesforce - Keep your UI Updated with latest data
  • Next PostField Service Lightning

Related Posts

Why Do We Use Lightning in Salesforce?
Lightning Salesforce

Why Do We Use Lightning in Salesforce?

How do I use lightning experience in Salesforce?
Lightning Salesforce

How do I use lightning experience in Salesforce?

Difference Between Lightning Components and Lightning Web Components
Lightning Salesforce

Difference Between Lightning Components and Lightning Web Components

Migrate to Flow Tool (Beta) – Salesforce Spring ’22 Release
Lightning

Migrate to Flow Tool (Beta) – Salesforce Spring ’22 Release

Leave a Reply (Cancel reply)

Your email address will not be published. Required fields are marked *

*
*

ABSYZ Logo

INDIA | USA | UAE

  • About us
  • Article & Blogs
  • Careers
  • Get In Touch
  • Our Expertise
  • Our Approach
  • Products
  • Industries
  • Clients
  • White Papers

Copyright ©2022 Absyz Inc. All Rights Reserved.

youngsoft
Copy
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “ACCEPT ALL”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent. Privacy Policy
Cookie SettingsREJECT ALLACCEPT ALL
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled

Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.

CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.

Functional

Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.

Performance

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Analytics

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.

Advertisement

Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.

Others

Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.

SAVE & ACCEPT