function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
eterpseterps 

My code coverage fails because of 3rd party managed packages

I'm trying to deploy a simple visualforce page with a custom controller class from my sandbox to production.  When I test my custom controller, I get 98% coverage on the class.  However, when I run "All Tests" the total coverage is 47% because several managed packages I have installed have low unit test coverage. 

 

These managed packages (non-profit starter pack) are installed in production, and are preventing me from deploying my own code because the code coverage is too low.  I cannot uninstall the packages because I will lose data.

 

I am using the  Inbound Change Set feature to import my code from my sandbox. It seems that the validate feature for this will only 'run all' unit tests, rather than only test the incoming code.

 

This is very frustrating.  Am I doing something wrong, or do I need to look for alternative ways to get my code into production?

 

Thanks,

Eric

sfdcfoxsfdcfox

The managed code in your organization must have at least 75% coverage to have been installed originally. When you use "run all tests", without attempting to deploy your own code, what is the result? Low code coverage from an installed package typically occurs because of the test aborting. This can happen when the administrator adds some code or configuration changes that affects the testing process.

 

Consider this scenario:

 

 

public class ManagedTestClass {
  public static void testMethod test() {
    Account a = new Account(Name='Test');
    insert a; // Trigger a managed Trigger.
    // do some more stuff with account a
  }
}

The developer creates a new account named Test, and when the module is installed, there is 99% coverage. Now, the system administrator decides that no account should ever have the name "Test" in their name, so they add the following validation rule:

 

 

 

 CONTAINS( Name , "Test" ) 

You can imagine what happens next. The validation will fail on the "insert a" line of code, thus wiping out the rest of the test and all future tests. If that happened approximately half way through the test process, the coverage of that managed code would hit 1% (because it literally failed on the second line of the test), and when averaged with the rest of the code, might easily drag the 99% coverage to 40-50%.

 

 

In this example, the system administrator for the organization the code was installed in was not aware that he "broke" anything when they made the new validation rule. In fact, the system could still be running 100% correctly, and only the test would fail.

 

Check your debug logs or deploy logs (i.e. Eclipse debug logs) to determine what broke, and then you can work on fixing it. Either your code is interacting with the managed code, or a setting in your organization has broken part of the managed testing.

hitzhitz

hi, eterps

 

please try to deploy only one page and related class [controller] with it test class from sandbox to production.  

eterpseterps

Well, after some experimenting, it turns out that MyProfilePageController was the culprit.  This is a class that is deployed automatically when setting up salesforce Sites.  Something in the testMethod of that class was causing an error and preventing the deployment of my own class.  I commented out the testMethod for MyProfilePageController, but this is what presumably caused test coverage to be too low.

 

I have no need for MyProfilePage nor MyProfilePageController at the moment, so I commented out all the code in each file.  Now everything works fine.  I still have no idea why MyProfilePageController was failing its test - this is a class created by Salesforce and deployed by Salesforce.  

 

The managed packages I was referring to still have less than 75% coverage, but it doesn't appear to be a problem (aside from being a red herring).  

pigginsbpigginsb

I'm aware that this is months after the fact, but someone may read these posts later today.

 

This link describes the difference between "Run All Tests" and "Calculate your organization's code coverage".

 

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

 

Run All Tests was indicating 64% coverage, while Calculate... was indicating 79% coverage, with a note that 75% is required.