You need to sign in to do that
Don't have an account?

need test class for apex class
iam new to apex.urgent need of test class for apex class
my apex class
public class MyController {
public ID accountId {get;set;}
public String email {get;set;}
public String getName() {
return 'MyController';
}
public Opportunity getOpportunity() {
return [select Account.Id, Account.name, Account.G_English_Name__c, Account.B_English_Name__c, Contact__r.name, Contact__r.MailingStreet,Contact__r.MailingCity,
Contact__r.MailingState, Contact__r.MailingPostalCode, Contact__r.MailingCountry from Opportunity
where id = :ApexPages.currentPage().getParameters().get('id')];
}
public PageReference sendPdf() {
PageReference pdf = Page.pdfgeneratortemplate;
// add parent id to the parameters for standardcontroller
pdf.getParameters().put('id',accountId);
// the contents of the attachment from the pdf
Blob body;
try {
// returns the output of the page as a PDF
body = pdf.getContent();
// need to pass unit test -- current bug
} catch (VisualforceException e) {
body = Blob.valueOf('Some Text');
}
Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
attach.setContentType('application/pdf');
attach.setFileName('testPdf.pdf');
attach.setInline(false);
attach.Body = body;
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setUseSignature(false);
mail.setToAddresses(new String[] { 'anand.2861985@gmail.com' });
mail.setSubject('PDF Email Demo');
mail.setHtmlBody('Here is the email you requested! Check the attachment!');
mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });
// Send the email
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Email with PDF sent to '+email));
return null;
}
}
Have you tried writing the test class at all? It's the best way to learn.
Wes
I agree with Wes, test classes are not as hard as they seem. Also, writing test classes is just as much a part of development as writing the production code itself.
Start with the beginnings of your first testmethod, and think about how you would recreate one of your test cases with Apex. In your case, you need to
Good luck!
Jeremy