+ Start a Discussion

Code Coverage Different In Eclipse

I'm a newbie and I'm stumped.  


When I run Apex Test Runner in Eclipse, it shows Average test coverage across all Apex Classes and Triggers is 41%.  

   (I read on a different post that if you clear the test history in Eclipse and run again, it will correct.  That didn't work in my case.  It still says 41%)


When I run overall code coverage in my developer account of SFDC, it says I'm at 77%.  


When I try to deploy from Elipse to my production server, it says Average test coverage across all Apex Classes and Triggers is 71%. 


Which one is right?  How can I deploy my project to my production server??


As a follow-up, I decided to create a sandbox from my production environment (instead of using a developer environment).  When I uploaded my code to my sandbox, the code coverage percentages now match the percentages shown by eclipse when trying to deploy to my production environment.  


So now I guess I'm changing my question to why is the code coverage in a development environment showing different percentages than a sandbox or production environment, when the code is 100% the same in all three environments? 



The test coverage numbers have been a bit screwy since Winter '12 or so.  You can't trust them really; at least for now.


However, your real issue is that you can't deploy.  Are you creating all data used in your test classes in your test classes or depending on data existing in the database?  If you're not creating the test data in your test class, you may experience different results across sandbox, dev and production orgs.  


Or if your test classes are working with Products and PriceBookEntries, you should set your test to "@isTest (SeaAllData=true)"


Regardless, try creating all data for testing in your test class; even users.


George Sowards

RedPoint Solutions