Top Banner
Josh Boyden Senior Quality Engineer, Salesforce IT [email protected] Test the Pyramid Larry Latimer MTS Software Engineer, Salesforce IT @77atimer Dreamforce 2016
32

Dreamforce 2016 - Test the Pyramid

Jan 09, 2017

Download

Technology

Josh Boyden
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Dreamforce 2016 - Test the Pyramid

Josh BoydenSenior Quality Engineer, Salesforce [email protected]

Test the Pyramid

Larry LatimerMTS Software Engineer, Salesforce IT

@77atimer

Dreamforce 2016

Page 2: Dreamforce 2016 - Test the Pyramid

Forward-Looking StatementsStatement 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 product or service availability, 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, new products and services, 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, the outcome of any litigation, risks associated with completed and any 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 year and in our quarterly report on Form 10-Q for the most recent fiscal quarter. These documents and others containing important disclosures 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 presentations, 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.

Page 3: Dreamforce 2016 - Test the Pyramid

Key Takeaways

Rediscover the Importance of TestingTechniques for Successful Testing on the PlatformValue and class injection for functional testsSelenium for UI, JavaScript and end to end tests

Page 4: Dreamforce 2016 - Test the Pyramid

Why Test?

Page 5: Dreamforce 2016 - Test the Pyramid

Why Test?

Requirement to Deploy• Meet the spirit of coverage not the percentage of coverage

Regression Testing• ...a type of software testing that verifies that software previously developed and tested still

performs correctly after it was changed or interfaced with other software. (wiki)• The goal is to identify bugs before your user or customers do.

Page 6: Dreamforce 2016 - Test the Pyramid

Why Test Differently?

Problems• Enterprise architecture is complex• Shared environment

Plan for a larger org

Page 7: Dreamforce 2016 - Test the Pyramid

Testing Pyramid

The concept of the Testing Pyramid originated from Mike Cohn and Martin FowlerFewer UI and End to End TestsMany fast running, fast result functional/ unit tests

Credit:@mikewcohn@martinfowler

Cost TimeUI

Unit

API

Page 8: Dreamforce 2016 - Test the Pyramid

Testing Pyramid and Salesforce

UIVisualforceLightningJavaScript

APIREST callsTriggers

UnitApex class methodsApex propertiesTrigger helper methods

Cost TimeUI

Unit

API

Page 9: Dreamforce 2016 - Test the Pyramid

Declarative ProcessValidations, Workflows

Positive and Negative TestsAll branches and states of your codeAll catch blocks

Methods and Properties

User Interface and JavascriptUsing Selenium or other UI testing tool

What to Test

Cost TimeUI

Unit

API

Page 10: Dreamforce 2016 - Test the Pyramid

Functional Unit vs UI

UnitMany

Fast

Focused

Method specific

UIFew

Slow

Complex

Business process focused

VS.

Page 11: Dreamforce 2016 - Test the Pyramid

Functional Testing

Page 12: Dreamforce 2016 - Test the Pyramid

DML IntensiveBuild, insert, update, query (SOQL) and assert then rollback records

Test Trigger to End of ProcessTriggers should require minimal testing so focus on classes and methods

Functional TestingConventional Testing

Page 13: Dreamforce 2016 - Test the Pyramid

No More DMLWrite your methods to handle in memory parameters

Inject Values into Class for TestingUse properties with @TestVisisbleIsolate your SOQL and DML statements

Inject Classes using Interfaces For Testing

Use mock classes to replace business logic not being tested

Test Run FasterNo longer a need for DML, database rollback or dependent codeLess chance of being blocked by governor limitsValidation and Workflows will no longer interfere with Apex testing

Functional TestingA Different Way of Testing

Page 14: Dreamforce 2016 - Test the Pyramid

Scenario Set the stage Contact count rollup

Page 15: Dreamforce 2016 - Test the Pyramid

Functional Tests@TestVisible Properties

Inject values into a class rather than using SOQL to query

Page 16: Dreamforce 2016 - Test the Pyramid

Functional TestsPopulate Variables in Memory

Populate the class variables and properties from in memory valuesAvoid SOQL for values

Page 17: Dreamforce 2016 - Test the Pyramid

Functional TestsUse JSON to Create Records

Serialize your SOQL results to use later for populating class properties

Page 18: Dreamforce 2016 - Test the Pyramid

Josh Boyden

Senior Quality Engineer, Salesforce IT

PLACE COMPANY LOGO HERE

Page 19: Dreamforce 2016 - Test the Pyramid

Selenium

Page 20: Dreamforce 2016 - Test the Pyramid

Tip of the Pyramid Creating UI and E2E tests with Selenium

Cost Time

UI

Unit

API

Page 21: Dreamforce 2016 - Test the Pyramid

What is Selenium?How many people have heard of Selenium?

Page 22: Dreamforce 2016 - Test the Pyramid

“Selenium automates browsers. That’s it!”http://www.seleniumhq.org/

Selenium HQ Free, open source Creates browsers Simulates user interaction

Page 23: Dreamforce 2016 - Test the Pyramid

Why use Selenium?Visualforce pagesJavaScriptComplex end to end workflows• By-pass governor limits

Page 24: Dreamforce 2016 - Test the Pyramid

Why use Selenium?Checkout – eCommerce website• Customer facing• UI intensive• JavaScript

Salesforce IT

Page 25: Dreamforce 2016 - Test the Pyramid

Scenario UI-intensive Account

edit page Auto-formatting

phone number inputTest Case Test the JavaScript on

the phone input

Example Test Case

Page 26: Dreamforce 2016 - Test the Pyramid

Demo!

Page 27: Dreamforce 2016 - Test the Pyramid

Selenium design conceptsEncapsulate pages as individual classes• Methods as accessors or simple actionsTest classes control logic and do assertions

Page object model

Page 28: Dreamforce 2016 - Test the Pyramid

Selenium design concepts Page object model

Page 29: Dreamforce 2016 - Test the Pyramid

Ready to get started with Selenium?Project source codehttps://github.com/joshboyden/Dreamforce16Selenium

Call to action

Page 30: Dreamforce 2016 - Test the Pyramid

Conclusion

Remember the Test Pyramid• Write lots of focused Apex functional tests• Use tools like Selenium to test end to end, UI and Javascript

Reduce Dependency on the Platform• Avoid DML when possible• Develop atomic tests using variable and class injection

Improve quality and productivity

Cost TimeUI

Unit

API

Page 31: Dreamforce 2016 - Test the Pyramid

Q&A

Larry Latimer @77atimer

Josh Boyden [email protected]

Selenium project https://github.com/joshboyden/Dreamforce16Selenium

Page 32: Dreamforce 2016 - Test the Pyramid

Thank Y u