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
Vinay Temburnikar 7Vinay Temburnikar 7 

Why do I get different code coverage results during change set validation vs developer console testing?

Hello, 

I made changes to a query in an apex class. From:

where A=x and B=true; To: where (A=x OR C=y) AND B=true

I thought this was simple enought to not warrant writing new apex test code, I had made the same change in a total of 5 instances in the apex class. And I was right, it showed 82% code coverage in the full sandbox after making these edits.

However, when I sent this change set containing only the single apex class to production, I'm getting a code coverage of 21% there. I text compared the test class in prod and the full sandbox, they are an exact match. 

I wonder what the problem is and why I'm getting this discrepency in code coverage. Any help would be much appreciated. 

Thanks in advance! 

vishal-negandhivishal-negandhi

Hi Vinay,
 

Are you creating all the test data needed for this class to run in any environment?
 

In most cases, if a test class has a better coverage in one instance than the other, it is mostly due to
- a related configuration missing (ex: an automation like process builder or a missing record type)
- mis-matching configs in the instances (ex: prod having more validation rules)
- ALL test data not created in test class