3rd Party Code Coverage is below 75%, is this bad? What to do?

We have a bunch of installed apps which are just killing our code coverage. We’re now down to only 77%, and all of the classes which are below 75% are from installed apps.

Has anybody else had this problem ? If so, what did you do (outside of uninstalling the apps) ? These are big name type apps also – Facebook, Twitter etc. They’re not just fly-by-night vendors who don’t feel like doing their test coding.

Is there anything to do for this ? How did you handle it ?

Thank you.

Answer

A few things to note here.

  • Managed package code is not included in the required code coverage
    calculation for deployment.
  • The 75% requirement is on all Apex code in your org’s namespace.
    Managed code has its own namespace, so it is not included.
  • When deploying to production, all tests in your org’s namespace
    will be run. Managed tests will not be run by default

When documentation states that you must have 75% code coverage in order to deploy, it can be misleading. You must have 75% code coverage on code with YOUR orgs namespace. Managed Packages have their own namespace, so the test run on that code isn’t evaluated on deployment.

A caveat here is that if you choose to ‘Run All Tests’ in your org, that does include managed package test code. So you could have 80% coverage on all your code, but when you ‘Run All Tests’ it shows you have 68% coverage. This would make you think you would not be able to deploy to this org, but you can, as the coverage for your org namespace is 80%, not the 68% its showing you.

Salesfroce accounts for this by giving you a link to estimate your code coverage, which will exclude the managed package test code. I fully admit this is not extremely evident in the UI as they really only tell you this on the tooltip bubble.

Try using the Estimate your organizations code coverage link. you will likely get a higher number that when you ‘Run all tests’.

enter image description here

As a side note, there are lots of things that could have ‘broken’ the test code in the managed package, but I find many times its as simple as one or more validation rules that were added to the org after the managed package was installed. Imagine the Package test method inserts a test Acccount. Now imagine after the installation of the package you added a validation rule that ensures an account has a picklist value on a certain field chosen. the managed package test code will now fail, which effects the test coverage. I know thats not what you were asking, but just thought I would add that as some additional info.

EDIT

You can also chose to run only the code from your Org namespace which will exclude the managed package code. If you go to Setup -> Develop -> Apex test Execution. Click the ‘Select Tests’ button and there is a drop down for either all namespaces, or just your namespace. This will allow you to run all tests only on your code.

enter image description here

EDIT

You can no longer clear code coverage from the Setup -> Develop -> Apex Classes menu as you could before. You know need to use the developer console for this.

https://success.salesforce.com/issues_view?id=a1p30000000T07jAAC

Attribution
Source : Link , Question Author : Zoom_v , Answer Author : Chris Duncombe

Leave a Comment