You need to sign in to do that
Don't have an account?
gb__
Test Class
Apex Test Class assistance needed
Hi all,
I'm struggling to get code coverage on my class. I've never written a test class for a Controller, only triggers, so I'm a bit lost.
Any help would be greatly appreciated.
Thanks,
Greg
Class
public with sharing class ShowAttachments_Controller { private List<Id> photoIds; private ApexPages.standardController controller; private List<Id> chatterphotoIds; private Acquisition_Report__c acquisition; public ShowAttachments_Controller(ApexPages.StandardController controller) { this.controller = controller; this.acquisition = (Acquisition_Report__c)controller.getRecord(); } public List<Id> photosfromchatter { get { if(chatterphotoIds == null) { chatterphotoIds = new List<Id>(); for(ContentVersion cnt : [select Id from ContentVersion ]) { chatterphotoIds.Add(cnt.Id); } } return chatterphotoIds; } } public List<Id> photos { get { if(photoIds == null) { photoIds = new List<Id>(); for(Attachment att : [select Id from Attachment where ParentId = :acquisition.Id]) { photoIds.Add(att.Id); } } return photoIds; } } public Integer totalPhotos { get { return photos.size(); } } }
Test Class
@isTest private class ShowAttachments_ControllerTest { static testMethod void validateShowAttachments_ControllerTest(){ { Account acc=new Account(Name='Acme Inc'); insert acc; test.startTest(); Attachment attach=new Attachment(); attach.Name='Unit Test Attachment'; Blob bodyBlob=Blob.valueOf('Unit Test Attachment Body'); attach.body=bodyBlob; attach.parentId=acc.id; insert attach; List<Attachment> attachments=[select id, name from Attachment where parent.id=:acc.id]; System.assertEquals(1, attachments.size()); String myString = 'StringToBlob'; Blob myBlob = Blob.valueof(myString); System.assertEquals('StringToBlob', myBlob.toString()); } test.stopTest(); } }
Try the code bellow changing it as needed:
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
All Answers
Try the code bellow changing it as needed:
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.