37
Top Testing Tips Data Creation, Web Callouts, and Automation Ami Assayag, CRM Science, @AmiAssayag Wes Nolte, Tquila, @WesNolte

Top Testing Tips

Embed Size (px)

Citation preview

Page 1: Top Testing Tips

Top Testing Tips

Data Creation, Web Callouts, and Automation

Ami Assayag, CRM Science, @AmiAssayag

Wes Nolte, Tquila, @WesNolte

Page 2: Top Testing Tips

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.

Page 3: Top Testing Tips

Ami Assayag

Principal Architect, CRM Science

PhillyForce Leader

@AmiAssayag

Page 4: Top Testing Tips

Wes Nolte

Director of Innovation, Tquila

Force.com MVP

London Dev Group Leader

@WesNolte

Page 5: Top Testing Tips

Matthew Botos

Model Metrics

a salesforce.com company

@BotosCloud

Couldn’t make it…

Page 6: Top Testing Tips

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

Page 7: Top Testing Tips

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.

Page 8: Top Testing Tips

Data Model

Page 9: Top Testing Tips

Business Logic is Completed!

Page 10: Top Testing Tips

And Now We Test

• Unit testing

• Integration testing

• Automated testing

Acceptance

Integration

Unit

Page 11: Top Testing Tips

Data Creation with

SmartFactory

Page 12: Top Testing Tips

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]

Page 13: Top Testing Tips

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]

Page 14: Top Testing Tips

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...

Page 15: Top Testing Tips

SmartFactory for Force.com

• Apex project

• Create test objects

• Autofill fields & lookups

Contact Account Custom

Object

Page 16: Top Testing Tips

Let’s Try SmartFactory

Page 17: Top Testing Tips

SmartFactory for Force.com

• Several utility methods

• Looking at metadata

• bit.ly/SmartFactory

Page 18: Top Testing Tips

Testing web callouts with

interfaces

Page 19: Top Testing Tips

Post to Twitter Architecture

Business Logic

Class Trigger

Callout Utility

Class

Page 20: Top Testing Tips

Integration Test

Page 21: Top Testing Tips

Post to Twitter Architecture (w/ an interface)

Business Logic

Class Trigger

Interface

Production

Implementation

Class

Mock

Implementation

Class

Callout Utility

Class

Page 22: Top Testing Tips

It All Starts With an Interface…

• Only contains method signatures.

• Implemented by other classes.

• Implement by providing code for interface methods.

Page 23: Top Testing Tips

Improve the Callout Class with the Interface

Suddenly our application logic is looking much cleaner.

Page 24: Top Testing Tips

Implementation Class #1: Mock

• Similar code to what we removed from the callout utility

Page 25: Top Testing Tips

Implementation Class #2: Production

• Performs actual callout.

Page 26: Top Testing Tips

Post to Twitter Architecture (w/ an interface)

Business Logic

Class Trigger

Interface

Production

Implementation

Class

Mock

Implementation

Class

Callout Utility

Class

Page 27: Top Testing Tips

Using The Interface: Test Method

Page 28: Top Testing Tips

Using The Interface: Business Logic

• Treat the interface the same here!

Page 29: Top Testing Tips

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

Page 30: Top Testing Tips

Automated testing and

continuous integration

Page 31: Top Testing Tips

Automated Testing and Continuous Integration

• Deployed tests are not run

• New code introduces new bugs

• Team introduces new bugs

Early detection of bug requires that you manually “Run All” tests

or implement full-blown CI… or does it?

Page 32: Top Testing Tips

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

Page 33: Top Testing Tips

Super Easy to Set Up

Page 34: Top Testing Tips

Test Results in Your Inbox

Page 35: Top Testing Tips

Open Source

• bit.ly/ForceAutoTest

• Pull requests are welcomed

Page 36: Top Testing Tips

Ami Assayag

Principal Architect

CRM Science

@AmiAssayag

Wes Nolte

Director of Innovation

Tquila

@WesNolte

Page 37: Top Testing Tips