+ Start a Discussion
Janardhana ReddyJanardhana Reddy 

Code Coverage showing 0% in Production

Hi All,
I am running test classes in my production Org, for some Classes it showing 0% Coverage for some classes it showing 97%.
The same test class tried run in my sandbox it showing code coverage for all classes.
Can any one tell me how to solve this Issue.
ManojjenaManojjena
Hi Janardhana,

Mostly this is bacause of some validation ,Some required field is there in production but not there in sandbox . So that the test records which are there in testcase  will execute without fail in sandbox ,however fail in production.

If any class has 0 % code coverage in production check the related test class and execute that and check the error ,you came to know the issue .
Janardhana ReddyJanardhana Reddy
Hi Manoj,
No Error but test classes run indivisually then it shows code coverage in sandbox.
ManojjenaManojjena
Hi Janardhana,
Have you executed the indivisul test class which i sshowing 0 % in production ?
 
Janardhana ReddyJanardhana Reddy
yes
Janardhana ReddyJanardhana Reddy
Hi Manoj,
executed in production test class, showing 0% in production. 

This nightmare for me from two days.
Cory CowgillCory Cowgill
Usually this happens when you are using the @SeeAllAnnotation or your Apex Classes are running on an older version (v27 for example). If so then Unit Tests can look at the data that exists in an Org and you can have different results between Production and Sandbox.

Please see this reference:
https://developer.salesforce.com/page/How_to_Write_Good_Unit_Tests

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_isTest.htm
Cory CowgillCory Cowgill
Do all your System Asserts pass? If you have 0% code coverage than I would assume that your unit tests System.Asserts are failing and telling you exactly what process is breaking. Again see the links I posted above on how to write good unit testss on the platform. For example if you have proper System.asserts and a Validation Rule that lives in Production but not Sandbox than the error will be presented to you cleanly. 

Writing proper Unit Tests with the best practices can help alleviate the time and stress involved in the scenario you are describing.

Best of luck.