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 like this:
System.assert(1 = 1) System.assert(BooleanVariable) System.assert(p != np)
The other two built-in assertion methods are really shorthand, convenience methods built on top of System.assert
. They are System.assertEquals(expected, actual)
and...