The Hammer

When is the last time that you ran the units tests on your org?

The results may surprise you. One of the things that makes Force.com development challenging is that there is the possibility of interaction between workflows, validation rules and other running unit tests in your force.com dev org“declarative” programming elements, and any Apex code and applications in your system. So it is very possible to have a unit test that passes when deployed to production, that later fails after someone adds a new workflow or validation rule.

Here’s a simple example of how this can happen. Let’s say a unit test exists that verifies an operation on account objects. To do so, the unit test will typically create a test account. Later, someone adds a new validation rule that requires an account field to be set. Now the unit test will fail – because the test accounts it creates won’t meet the validation rule.

Why does this matter?

First, because a failing unit test can prevent you from performing code updates until the problem is resolved. This can cause delays and unexpected costs when developing or updating code as it becomes necessary to analyze and fix unit tests before deployment.

So clearly it’s a good idea to run your unit tests after every change to your org configuration.

But there’s another reason you should do this.

About every four months, Salesforce performs a major software release. Have you ever wondered how they make sure that their updates don’t break your existing code? One way they do this is using a test called the hammer – they literally run every unit test on every organization and compare the results on the existing code against the new version.

If you have failing unit tests, they won’t count during the hammer test – as a failure on the new version of Salesforce won’t indicate a change in behavior. But if your unit tests pass, but fail during the hammer test – Salesforce will know that there’s a problem with the new version, and they’ll fix it before it goes to release.

So run your unit tests on a regular basis and after every configuration change and help keep Salesforce the reliable platform that we’ve all come to count on.

Hint: Under Apex Test Execution options,  always select the option “Disable Parallel Apex Testing” – it eliminates false errors on some applications.

Dan Appleman

About Dan Appleman

As Full Circle Insights’ CTO, Dan Appleman brings a broad technology experience to our customers. In addition to having supported over 30 Salesforce.com implementations with technology solutions, Dan is also the author of the book "Advanced Apex Programming for Salesforce.com and Force.com" and has been a speaker at Dreamforce since 2012. Previously, he was the founder of Desaware, Inc. a developer of add-on products for Microsoft Visual Studio, a co-founder of Apress publishing, and the author of numerous books and articles.