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
Abhishek Singh 88Abhishek Singh 88 

code coverage issue during deployment

Hi Developers,
I am Facing strange issue. My class has 94% code coverage, i checked in eclipse as well. but while deploying this class it shows code coverage failure, only  61% code coverage, Even though i used RUN specified tests option.

Any help on this will be appriciated.
Best Answer chosen by Abhishek Singh 88
Shivdeep KumarShivdeep Kumar
Hi Abhishek,

Your sandbox and production instances have totally different data, so your tests will run on different data as well.
The way around this is to create all new records in the beginning of your test class.  Make sure not to use the SeeAllData=true annotation!

Also - your production org might have certain configurations that may be generating errors in your test class and lowering its coverage.  These could be validation rules, custom settings, workflows, etc.  

Please let me know if this help !

Thanks
Shivdeep

All Answers

Shivdeep KumarShivdeep Kumar
Hi Abhishek,

Your sandbox and production instances have totally different data, so your tests will run on different data as well.
The way around this is to create all new records in the beginning of your test class.  Make sure not to use the SeeAllData=true annotation!

Also - your production org might have certain configurations that may be generating errors in your test class and lowering its coverage.  These could be validation rules, custom settings, workflows, etc.  

Please let me know if this help !

Thanks
Shivdeep
This was selected as the best answer
Abhishek Singh 88Abhishek Singh 88
Thanks shivdeep..it was really helpful.
I have created new set of test data.