[SalesForce] Stumped! Sandbox code coverage 89%, no org data in test class, yet deploy error – average code coverage is 0%

I created a rather simple Apex class VF11_controller in sandbox, which I'm looking to deploy to production. This apex class has one dependency, a VF page, which I added too in the change dataset. After creating the simplest test class for the controller in sandbox, I see a code coverage of 89%, good enough for deployment right:

enter image description here

However, after upload and attempt to deploy with the same user in production, I get the dreaded error:

enter image description here

Something is way off here cause it says test coverage is 0%! I'm sharing as much info as possible so the cause of error can be identified and removed. Here is my test class:

@isTest(SeeAllData=true) 
class Test_VF11_Controller{ 
    static testMethod void test(){ 
        account acc = new account(name='Acc1'); 
        insert acc; 
        contact cont = new contact(firstname='Jessie',lastname='Brown',email='jjbrown@gmail.com',accountid=acc.id); 
        insert cont; 
        VF11_Controller con = new VF11_Controller(new ApexPages.StandardController(cont));        
        attachment att = new attachment(name='newAtt',body=blob.ValueOf('random text'),parentId=con.contact_id);
        insert att;
        con.cc  = 'cctest@email.com';
        con.bcc = 'bcctest@email.com';     
        con.attachment1.name = 'upload';
        con.attachment1.body = blob.ValueOf('upload random text');           
        boolean selected = false;
        VF11_Controller.attachwrapper wrap = new VF11_Controller.attachwrapper(att);
        wrap.acc = att;
        wrap.selected = false;
        con.getSelectedattachments();
        con.getSelected();
        wrap.selected = true;
        con.getSelected();
        con.attach_new(); 
        con.sendEmail();
        } 
}

And finally, here's the entire red and blue color code of the Apex controller (89% covered) that I need to deploy to prod (please zoom in to view better):
enter image description here

What could be causing this? Also, I noticed something pretty strange – occasionally after a refresh or returning to the page of apex classes, I see the code coverage of VF11_controller down to 0%! But I always made sure it's 89% last when I check, right before uploading from sandbox.

I also tried removing the hard-coded email template ids from the controller and then deploying; no easy luck.

Best Answer

Is there a chance that you added a required field, validation rule, or something in production that your unit test class is not expecting (which could cause the unit tests to fail)? This could result in 0% unit test coverage.

Also, are you sure you are deploying your test class?

Related Topic