5

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='[email protected]',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  = '[email protected]';
        con.bcc = '[email protected]';     
        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.

4
  • 6
    This may be too simple, but did you add the test class to the change set? Aug 16, 2013 at 23:27
  • What is the code coverage in production before you push the change set? Aug 17, 2013 at 4:19
  • Thanks gentlemen, I apparently wasn't aware that the test class needs to be included. Sorry, first time deployment.
    – Rosh
    Aug 18, 2013 at 5:01
  • Cannot believe how dump I was not to include the test classes. Feb 8, 2016 at 13:51

1 Answer 1

8

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?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .