6

I am working on a salesforce managed package project which is not in DX. I want to start writing unit test cases for lightning component using lightning test service. I have gone through the github tutorial on how to use LTS (https://github.com/forcedotcom/LightningTestingService) and have installed the unmanaged package manually. I am not sure where should I add my test files? Should I create a new folder tests under src folder ? or should I add it outside src folder? or should I create one test lightning app/component? and How do I run these tests ?

Typical SF Project Structure

6

Is it possible for you to switch to Salesforce DX source format for your development (For example see this blog and this trailhead module)? Asking because in my personal experience sfdx format provides more control/flexibility around the organization of metadata which LTS relies on.

That said, it is possible to use the unmanaged packages provided by LTS without sfdx CLI. The steps would be,

  1. Install jasmine or mocha version of the package into your developer/sandbox org via links provided at https://github.com/forcedotcom/LightningTestingService/releases
  2. Create a javascript static resource (lets call it myTests.resource) and put your tests in it (using jasmine/mocha format).
  3. Create a wrapper test suite app (lets call it myJasmineTests.app) that composes lts_jasmineRunner component and provides it a list of static resource files containing the tests,

<aura:application> <c:lts_jasmineRunner testFiles="{!join(',',$Resource.myTests)}" /> </aura:application>

  1. Navigate to the app using the browser for a manual run.
  2. For CI integration, write a web-driver script to programmatically hit the app and wait for test run to complete.

As Metadata API source format doesn't allow for structuring of the metadata into multiple directories/packageDirectories, the test files you create will essentially live alongside rest of your metadata (e.g. in staticresources, aura dirs) but you'll just not include them in your managed package. Salesforce DX source format on the other hand enables you to split up the source enabling separation of test/dev metadata.

  • Sorry, its not possible to migrate to Salesforce DX in near future. Thanks for your response. I could get it to work using existing setup. Though existing code requires some refactoring to be able to write some valid unit tests for lightning components. – user360 Jan 31 '18 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.