Teach Me Salesforce

A community approach to learning salesforce.com

Archive for the ‘Validation’ Category

Unit Tests: Not Just for Dev – Idea 0

leave a comment »

This post is kicking off a series of posts about how Salesforce Admins & Developers can use Unit Tests for more than just testing Apex. The target audience is Admins who haven’t written Unit Tests. The ideas for Unit Tests here are intended to be easily copied and modified by anyone with System Admin access, a Sandbox or Developer Edition Org and a need to add a little more protection to their hard-won successes in building their org.

Unit Tests are designed to test Apex Triggers and Classes. They are required for deploying them to Production, but more important they are an essential tool to ensure that your logic, both Apex and declarative, does what it’s supposed to do, and nothing more or less.

But how else can they be useful?

Protection Integrations: Many Salesforce Orgs are now integrated with other applications and rely on the fields in Salesforce to, well, exist. And not to change or get locked down. Unit tests can be used to protect all the fields an integration uses against deletion, against changes to field type or restrictions by Field-level Security or Validation Rules.

Testing Declarative-only Apps: All those Clicks-not-Code components can add up to a complex series of Workflow Rules, Formula Fields and Validation Rules where you’ve got an application that is vulnerable to even slight changes. Unit tests can be used to ensure that a series of related Rules and Fields perform as expected, and that changes don’t disrupt the outcome.

And that application’s complexity can become difficult to test when there are hundreds of combinations of fields and their values. Throw in the ability to mass edit records in Views or Data Loader and you’ve got hours of manual tests to perform. Unit Test can be written to try all the combinations you want to throw at it, for hundreds of records.

The Ideas and Unit Tests in this series are all written using the sample data and metadata from the Developer Edition Orgs. Where necessary, I’ll add some new Workflow Rules, Validation Rules and Fields to come up with viable scenarios. If you don’t already have a Developer Edition org, you can get one (or one hundred) free Orgs at developer.force.com.

Because it’s so handy, we’ll use the Developer Console to write and run the Unit Tests, but you can also use the Force.com IDE for Eclipse, MavensMate or even the declarative interface.

You won’t need to know much Apex. I’ll attempt to explain the parts that are not intuitive, or just advise you to do-as-I-do if the explanation won’t help (or I don’t know either).

So put your pencils down, Testing time is up: Idea 1


Written by Always Thinkin

August 3, 2014 at 3:28 pm

Posted in Apex, Intermediate, Validation, Workflow

Tagged with ,