+ Start a Discussion

Test Code for a Class

Im having a problem as explained here. I was told that it is because of a lack of test coverage but Im new to this and dont know how to write test code to cover the class. How do I write this code? Thanks in advance for your help!



Here is the code for my class:


public class GLeadExtension { public Lead Lead1 ; public GLeadExtension(ApexPages.StandardController controller) { Lead1 = (Lead)controller.getRecord(); Lead1.D1_Owner__c = '0017000000NnIX7'; Lead1.D2_Owner__c = '0017000000NnIX7'; } public PageReference step1() { return Page.mhform1; } public PageReference step2() { return Page.mhform2; } public PageReference step3() { return Page.mhform3; } public PageReference step4() { return Page.mhformconfirm; } public PageReference save() { PageReference pdf = Page.mhformconfirm; pdf.getParameters().put('p','p'); pdf.setRedirect(false); Blob b = pdf.getContent(); Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); email.setSubject('Conveying Application request'); String [] toAddresses = new String[] {'margiro@piab.com'}; email.setToAddresses(toAddresses); email.setPlainTextBody('An order has been placed for a conveyor'); Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment(); efa.setFileName(Lead1.company + '.pdf'); efa.setBody(b); email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa}); Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); //leadsave(); //this.standardController.save(); insert Lead1; //this is my logic for where I want to go after stuff is saved PageReference nextPage = new PageReference('/apex/mhformendpage'); nextPage .setRedirect(true); return nextpage; //return page.mhformendpage; } }





The introduction to writing test coverage is at




That would be a good place to start.