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.
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Df12 Top Testing Tips
1. Top Testing Tips
Data Creation, Web Callouts, and Automation
Ami Assayag, CRM Science, @AmiAssayag
Wes Nolte, Tquila, @WesNolte
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.
4. Wes Nolte
Director of Innovation, Tquila
Force.com MVP
London Dev Group Leader
@WesNolte
5. Couldn’t make it…
Matthew Botos
Model Metrics
a salesforce.com company
@BotosCloud
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. Our assigned project
You've 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.
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. 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. 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. SmartFactory for Force.com
• Apex project
• Create test objects
• Autofill fields & lookups
Custom
Contact Account
Object
21. Post to Twitter Architecture (w/ an interface)
Business Logic Callout Utility
Trigger
Class Class
Mock
Implementation
Class
Interface
Production
Implementation
Class
22. It all starts with an Interface…
• Only contains method signatures.
• Implemented by other classes.
• Implement by providing code for interface methods.
23. Improve the callout class w/ the interface
Suddenly our application logic is looking much cleaner.
26. Post to Twitter Architecture (w/ an interface)
Business Logic Callout Utility
Trigger
Class Class
Mock
Implementation
Class
Interface
Production
Implementation
Class
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
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. 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