Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to Lightning Component Testing

Introduction to Lightning Component Testing

Lightning is the new Salesforce framework and nowadays there is no integrated testing tool provided by the platform or with an easy access. So, how to assure the quality of our code from a testing standpoint? We are going to present you two approaches to handle this with some easy code examples.

Gonzalo Miraballes

March 10, 2016
Tweet

More Decks by Gonzalo Miraballes

Other Decks in Technology

Transcript

  1. Safe Harbor Safe harbor statement under the Private Securities Litigation

    Reform Act of 1995: This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services. The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our service, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, risks associated with possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our service and successful customer deployment, our limited history reselling non-salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-K for the most recent fiscal quarter ended July 31, 2011. This document and others are available on the SEC Filings section of the Investor Information section of our Web site. Any unreleased services or features referenced in this or other press releases or public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.
  2. Follow UYSDUG for the latest news •  @uysdug #uysdug • 

    /Uruguay-Salesforce-Developer-User-Group/ •  www.uysdug.com
  3. Lightning Component challenges •  Components are isolated •  JS in

    controller and helpers •  Cannot capture coverage •  How to trigger tests? CI? Solutions •  xUnit.js •  Aura framework test library
  4. xUnit.js An xUnit style framework for javascript, designed to facilitate

    writing unit tests. It includes •  A script-engine agnostic console runner •  No web server needed •  No browser needed •  Just an engine, the test file and the file under test •  Mechanisms to attribute tests declaratively
  5. Concepts •  Facts •  Single behavioral promise •  Should be

    named after the promise of behavior they exercise •  Fixture •  Encapsulate tests for common behaviors •  Execute all registered Fixtures and Facts when run
  6. Concepts (2) •  Mocks •  Provides an execution context • 

    Overrides known object or property •  Reverted after test execution •  Useful for injecting code •  Global object available at any depth
  7. Supported Host Engines •  xUnit.js console runner comes with built-in

    support for the following popular JS engines •  v8 (Chrome) •  SpiderMonkey (Firefox) •  Rhino (Java) •  Chakra (IE9+) •  Node.js •  Phantom.js
  8. Tools •  Aura components are instantiated on the server or

    client, depending on the component, so we need tools to test the components on both ends. •  Tools for browser and device testing include: i.  WebDriver Tests (integration tests) •  Tools for headless (such as assert payload and response codes) include: i.  HTTP Client Tests ii.  PhantomJS •  We want to adopt the right set of testing tools to cover our feature set.
  9. Aura Components Tests – JavaScript Component Tests JSTest •  Aura

    JSTests are an alternative to Java-based WebDriver tests. •  They allow you to write tests in JavaScript and to package the tests with the target component. •  JavaScript tests make it easy for you to interact with the component and assert on conditions using Aura's JavaScript API.
  10. Aura Components Tests – JavaScript Component Tests JSTest • Conventions a. Aura

    JavaScript tests are part of the component bundle and live in the same directory as the component markup.
  11. Aura Components Tests – JavaScript Component Tests JSTest •  Attributes

    Passed in as query parameters (as in manual testing) so that they handle only deserializable attribute types. Case-level attributes are merged with suite-level attributes, overriding any duplicates. •  Labels Arbitrary test labels. Case-level labels are merged with suite-level labels. •  Browsers By default, tests execute on all browsers. To run tests on a subset of browsers, list them ['IE8', 'SAFARI']. Exclude a browser from the test by prefixing the browser name with a hyphen ['-IE8'].
  12. Aura Components Tests – JavaScript Component Tests JSTest •  Mocks

    Mock server definitions to isolate dependencies. Case-level mocks are merged with suite-level mocks, overriding any duplicates. •  Stubs Replace a method, function or an entire object with a version that produces hard- coded responses. •  Tests One or more test functions. After each function, the framework waits for any pending server actions initiated by $A.test.callServerAction or by $A.test.addWaitFor.
  13. Aura Components Tests – JavaScript Component Tests JSTest •  Aura

    framework – Test Class Utility functions for component testing, accessible using $A.test. $A.test.assertEquals('http://gus/', component.getElement().href); $A.test.addWaitFor(true, function(){return window.fired.length > 0;}); $A.test.assertNotNull(argument1, 'The first argument received was null');
  14. Thank You! Introduction to Lightning Component Testing Uruguay Salesforce Developer

    Group March 10th, 2016 #UYSDUG Pablo Fernandez Team Lead / Developer @pablomff86 Gonzalo Miraballes QA Lead @lookvalley_ #uysdug