Assertions

If you take nothing else away from this chapter, let it be this—tests without assertions are not tests, but liabilities. Without the assert calls, you cannot check the outcome of your executed code block to see if it functioned properly. That's why I refer to test methods without assert calls as liabilities. Inevitably, when the code fails for whatever reason, you're accountable for the consequences. At 3am. On a Saturday. It's even worse, if your code is mission critical and fails at the quarter's end! Practice safe testing, use asserts.

The Salesforce1 platform provides us with three basic assertion methods. The first method, System.Assert(expression), evaluates the expression within for a Boolean true or false. Thus, you can use it ...

Get Mastering Application Development with Force.com now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.