+ Start a Discussion

Production/Developer edition test coverage problem

In salesforce Production/Developer edition test coverage shows only 13%.But same code in trail edition test coverage shows 88% And salesforce Production/Developer edition system.assert shows error "variable doesnot exist But in Trail edition no errror Code Visualforce page DocumentEmailer Apex class DocumentEmailController public with sharing class DocumentEmailController { public ID documentId {get;set;} public String email {get;set;} public List documents { get { if (documents == null) { documents = new List(); documents.add(new SelectOption('01570000001NZDn','Cup of Coffee? - DOC')); documents.add(new SelectOption('01570000001NZDi','Workflow Cheatsheet - PDF')); } return documents; } set; } public PageReference sendDoc() { Document doc = [select id, name, body, contenttype, developername, type from Document where id = :documentId]; Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment(); attach.setContentType(doc.contentType); attach.setFileName(doc.developerName+'.'+doc.type); attach.setInline(false); attach.Body = doc.Body; Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setUseSignature(false); mail.setToAddresses(new String[] { email }); mail.setSubject('Document Email Demo'); mail.setHtmlBody('Here is the email you requested: '+doc.name); 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 Document sent to '+email)); return null; } } Test code Test_DocumentEmailer @isTest private class Test_DocumentEmailer { static Document document; static { document = new Document(); document.Body = Blob.valueOf('Some Text'); document.ContentType = 'application/pdf'; document.DeveloperName = 'my_document'; document.IsPublic = true; document.Name = 'My Document'; document.FolderId = [select id from folder where name = 'My Test Docs'].id; insert document; } static testMethod void testDocumentEmailer() { PageReference pref = Page.DocumentEmailer; DocumentEmailController con = new DocumentEmailController(); Test.startTest(); System.assertEquals(2,con.documents.size()); // populate the field with values con.documentId = document.id; con.email = 'test@noemail.com'; // submit the request pref = con.sendDoc(); Test.stopTest(); } } In test code System.assertEquals(2,con.documents.size()); shows error Variable doesnot exist documents

Can I suggest you reformat this, once you do that we may be able to read this and assist.

Post Not Clear



I would suggest you commenting out all the system assert statements in your test classes. It is not necessary for deployment.



thanks for ur reply now the test coverage increased from 18% to 48%.But i need 75% test coverage