+ Start a Discussion
EJWEJW 

Unit Test Code Coverage and Managed Packages

We get lots of questions on code coverage and deployment and how those are impacted by managed packages (and managed package unit test failures).  I was hoping that someone at SFDC could confirm/explain that managed packages are not considered as part of your code coverage percentage for deployment or on the Apex Classes page (where you click the code coverage link to calculate your org's coverage) and that managed package unit test failures will not prevent customer code from deploying to production (unless they've explicitly added the runAllTests="true" option in ant deployment).

 

I'd like to have a good authoritative response from an internal SFDC development resource to send to customers as they quite frequently get different answers on this issue when asking SFDC support.  I'm not looking for a huge response, just a basic explanation and confirmation that managed packages are no longer part of the equation when it comes to customer code.

 

Here are some resources I've found that give a brief mention that managed packages are not considered when calculating code coverage:

 

http://na5.salesforce.com/help/doc/en/code_run_tests.htm

 

Note this statement:

 

75% of your Apex code must be covered by unit tests, and all of those tests must complete successfully.

Note the following:

  • When deploying to a production organization, every unit test in your organization namespace is executed.
  • Calls to System.debug are not counted as part of Apex code coverage.
  • Test methods and test classes are not counted as part of Apex code coverage.
  • While only 75% of your Apex code must be covered by tests, your focus shouldn't be on the percentage of code that is covered. Instead, you should make sure that every use case of your application is covered, including positive and negative cases, as well as bulk and single record. This should lead to 75% or more of your code being covered by unit tests.

My comment: Your organization namespace doesn't include managed packages as each managed package has it's own namespace.

 

Also: https://na5.salesforce.com/help/doc/en/code_manage_packages.htm

 

Specifically this note near the bottom:

 

The code coverage value computed by Calculate your organization's code coverage might differ from the code coverage value computed after running all unit tests using Run All Tests. This is becauseCalculate your organization's code coverage excludes classes that are part of installed managed packages while Run All Tests doesn't.

 

Thanks,

Best Answer chosen by Admin (Salesforce Developers) 
kaplanjoshkaplanjosh

Hi EJ:

 

  • 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.  
  • If the deployment package explicitly marks runAllTests to true, managed tests will also run.  These will need to execute without any failures should the flag be set.  Despite this, the 75% requirement for code coverage is still only on unmanaged code.

Thanks,

Josh

 

 

All Answers

EJWEJW

Still hoping to get a response from SFDC on this.

EJWEJW

Could I please get a response from Salesforce.com developer support?

 

Thanks,

kaplanjoshkaplanjosh

Hi EJ:

 

  • 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.  
  • If the deployment package explicitly marks runAllTests to true, managed tests will also run.  These will need to execute without any failures should the flag be set.  Despite this, the 75% requirement for code coverage is still only on unmanaged code.

Thanks,

Josh

 

 

This was selected as the best answer
EJWEJW

Thanks for the response Josh, I appreciate it.  I'll pass this information along to our customers.