Df12 Top Testing Tips


Published on

Slides from the Dreamforce 2012 session "Top Testing Tips: Data Creation, Web Callouts, and Automation"
Description: Take your Apex code testing to the next level with sample code and open source libraries that make these advanced topics easy. Save time with SmartFactory, which automatically creates complex test data for tests isolated from your regular data. Learn how to test web callouts cleanly and completely using interfaces and mocks. Finally, make sure all your team's tests run regularly with native Force.com automation that takes a fraction of the time of full continuous integration.

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Df12 Top Testing Tips

  1. 1. Top Testing TipsData Creation, Web Callouts, and AutomationAmi Assayag, CRM Science, @AmiAssayagWes Nolte, Tquila, @WesNolte
  2. 2. 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 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 intellectual property and other litigation, 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-Q for the most recent fiscal quarter ended July 31, 2012. This 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.
  3. 3. Ami AssayagPrincipal Architect, CRM SciencePhillyForce Leader@AmiAssayag
  4. 4. Wes NolteDirector of Innovation, TquilaForce.com MVPLondon Dev Group Leader@WesNolte
  5. 5. Couldn’t make it…  Matthew Botos Model Metrics a salesforce.com company @BotosCloud
  6. 6. Our agenda for today• Review our assigned project• Review top testing tips: • Data creation with SmartFactory • Testing web callouts with interfaces • Automated testing and continuous integration
  7. 7. Our assigned projectYouve just been hired as a developer on an existing project and given this story to implement: As a conference attendee, I want to create a Registration for a Session, and post it to my Twitter account.
  8. 8. Data Model
  9. 9. Business logic is completed!
  10. 10. And now we test• Unit testing• Integration testing Acceptance• Automated testing Integration Unit
  11. 11. Data creation withSmartFactory
  12. 12. Let’s Make a Registration System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Session__c, Contact__c]: [Session__c, Contact__c]
  13. 13. Oops, Let’s Make a Session System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Start_Date_Time__c]: [Start_Date_Time__c]
  14. 14. Continue creating test data • Identify all objects and related objects • Identify all required fields • Identify valid values for all required fields • Populate all required fields • Rinse & repeat • OR...
  15. 15. SmartFactory for Force.com • Apex project • Create test objects • Autofill fields & lookups Custom Contact Account Object
  16. 16. Let’s Try SmartFactory
  17. 17. SmartFactory for Force.com • Several utility methods • Looking at metadata • bit.ly/SmartFactory
  18. 18. Testing web callouts withinterfaces
  19. 19. Post to Twitter Architecture Business Logic Callout Utility Trigger Class Class
  20. 20. Integration Test
  21. 21. Post to Twitter Architecture (w/ an interface) Business Logic Callout Utility Trigger Class Class Mock Implementation Class Interface Production Implementation Class
  22. 22. It all starts with an Interface… • Only contains method signatures. • Implemented by other classes. • Implement by providing code for interface methods.
  23. 23. Improve the callout class w/ the interface Suddenly our application logic is looking much cleaner.
  24. 24. Implementation Class #1: Mock • Similar code to what we removed from the callout utility
  25. 25. Implementation Class #2: Production • Performs actual callout.
  26. 26. Post to Twitter Architecture (w/ an interface) Business Logic Callout Utility Trigger Class Class Mock Implementation Class Interface Production Implementation Class
  27. 27. Using The Interface: Test Method
  28. 28. Using The Interface: Business Logic • Treat the interface the same here!
  29. 29. Using interfaces in apex testing• Summary of advantages • Tried and tested through Java, .Net and others • Interfaces decouple code and provide consistency • Fewer hacks to get tests to work correctly • Improved code coverage • Can test multiple callout situations with different “dummy” data • bit.ly/ApexCalloutTest
  30. 30. Automated testing andcontinuous integration
  31. 31. Automated testing and continuous integration • Tests are only run on deployment or explicitly in UI • New production or test code might introduce bugs • Bugs multiplied in complex team dev scenarios Early detection of bug requires that you manually “Run All” tests or implement full-blown CI… or does it?
  32. 32. Automated Testing for Force.com (App) • Free App that installs as a managed package with just a few clicks • Runs 100% on the Force.com Platform
  33. 33. Super Easy to Set Up
  34. 34. Test Results in Your Inbox
  35. 35. Open Source• bit.ly/ForceAutoTest• Pull requests are welcomed
  36. 36. Ami Assayag Wes NoltePrincipal Architect Director of Innovation CRM Science Tquila @AmiAssayag @WesNolte