top testing tips

Post on 07-Jul-2015

255 Views

Category:

Documents

4 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Top Testing Tips

Data Creation, Web Callouts, and Automation

Ami Assayag, CRM Science, @AmiAssayag

Wes Nolte, Tquila, @WesNolte

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.

Ami Assayag

Principal Architect, CRM Science

PhillyForce Leader

@AmiAssayag

Wes Nolte

Director of Innovation, Tquila

Force.com MVP

London Dev Group Leader

@WesNolte

Matthew Botos

Model Metrics

a salesforce.com company

@BotosCloud

Couldn’t make it…

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

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.

Data Model

Business Logic is Completed!

And Now We Test

• Unit testing

• Integration testing

• Automated testing

Acceptance

Integration

Unit

Data Creation with

SmartFactory

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]

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]

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

SmartFactory for Force.com

• Apex project

• Create test objects

• Autofill fields & lookups

Contact Account Custom

Object

Let’s Try SmartFactory

SmartFactory for Force.com

• Several utility methods

• Looking at metadata

• bit.ly/SmartFactory

Testing web callouts with

interfaces

Post to Twitter Architecture

Business Logic

Class Trigger

Callout Utility

Class

Integration Test

Post to Twitter Architecture (w/ an interface)

Business Logic

Class Trigger

Interface

Production

Implementation

Class

Mock

Implementation

Class

Callout Utility

Class

It All Starts With an Interface…

• Only contains method signatures.

• Implemented by other classes.

• Implement by providing code for interface methods.

Improve the Callout Class with the Interface

Suddenly our application logic is looking much cleaner.

Implementation Class #1: Mock

• Similar code to what we removed from the callout utility

Implementation Class #2: Production

• Performs actual callout.

Post to Twitter Architecture (w/ an interface)

Business Logic

Class Trigger

Interface

Production

Implementation

Class

Mock

Implementation

Class

Callout Utility

Class

Using The Interface: Test Method

Using The Interface: Business Logic

• Treat the interface the same here!

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

Automated testing and

continuous integration

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?

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

Super Easy to Set Up

Test Results in Your Inbox

Open Source

• bit.ly/ForceAutoTest

• Pull requests are welcomed

Ami Assayag

Principal Architect

CRM Science

@AmiAssayag

Wes Nolte

Director of Innovation

Tquila

@WesNolte

top related