One of the ways that code coverage drops which many people aren't aware of is that when you enable certain features of Salesforce, you get new controllers automatically installed into your org that don't always have 75% code coverage or that contain methods that will fail without intervention on your part. These controllers need to have additional test code added to them that are customized to meet the requirements for your specific org.
One example that comes to mind is when you enable Communities. Expect 1 of the 11 test methods to fail. Ignoring that 1 method has failed, here's the coverage that gets listed for the controllers:
- ChangePasswordController (100% class code coverage 6/6)
- CommunitiesLandingController (33% class code coverage 1/3)
- CommunitiesLoginController (100% class coverage 5/5)
- CommunitiesSelfRegConfirmController (100% class code coverage 1/1)
- CommunitiesSelfRegController (84% class code coverage 28/33)
- MyProfilePageController (87% class code coverage 36/41)
- SiteLoginController (100% class code coverage 6/6)
- SiteRegisterController (82% class code coverage 23/28)
- ForgotPasswordController (88% class code coverage 8/9)
- Average code coverage for above code = 86% (114/132)
If you enable Chatter Answers, including enabling it for your Community, expect 2 of the 3 methods to fail. Ignoring that two methods have failed, here's the default coverage you get:
- ChatterAnswersAuthProviderRegistration (51% code coverage 18/35)
- ChatterAnswersRegistration (100% code coverage 4/4)
- chatter_answers_question_escalation_to_case_trigger (42% code coverage 6/14)
- Average code coverage for above code = 53% (28/53)
Further, in SU15, Salesforce instituted New Code Coverage Calculation for Multiline Statements. Prior to SU15, if you had code written as multi-line statements, each line counted as a single line which potentially had the effect of increasing your coverage. That's no longer the case. It now depends on whether or not the line is actually executed or evaluated during the test class. Here's an example where code coverage could go down:
//Lets say that opp.Id == null
//Previously, this would have been evaluated as four lines of code
//Under new rules, this will now be evaluated as only 1 line of code because
//1st line fails & no need to execute additional lines in test
if(opp.Id != null
&& another var not eval
&& another var not eval
&& another var not eval)
{ //always ignored and not counted in coverage
doSomething(); //Doesn't get executed under old or new rules when if condition isn't met
Under the above scenarios, you coverage could easily go down depending on whether or not you've covered all the compound lines in your if statement along with the order in which they're listed. So, this is something you'll want to be aware of that could be affecting your code coverage. There are other things that are covered in the link I've provided above.