You need to sign in to do that
Don't have an account?
sfdc18
test class not covering controller code
Hi,
I need a help in test coverage for a controller having wrapper class. Currently it is covering only 60% of code.
Apex Controller :
Test Class :
@isTest(SeeAllData = true) public class CopyAttachmentControllerTest { private static RecordType supportCaseRecordType = [SELECT Name, Id FROM RecordType WHERE Name ='Support Case' AND SObjectType = 'Case']; private static RecordType L2CaseRecordType = [SELECT Name, Id FROM RecordType WHERE Name ='L2 Case' AND SObjectType = 'Case']; static testmethod void CopyAttachmentTestCase(){ Account testAccount = new Account(); testAccount.Name = 'test'; insert testAccount; Contact testContact = new Contact(); testContact.LastName = 'Test Name'; testContact.AccountId = testAccount.Id; insert testContact; Product2 testProduct = new Product2(); testProduct.Id = null; testProduct.Name = 'Test Product Name'; testProduct.Product_Category__c = 'Category'; testProduct.Product_Family__c = 'Family'; testProduct.Product_Sub_family__c = 'Sub-Family'; insert testProduct; Case testCase = new Case(); testCase.RecordTypeId = supportCaseRecordType.Id; testCase.Summary__c = 'Summary'; testCase.Description = 'Description'; testCase.Origin = 'Email'; testCase.Status = 'New'; testCase.I_Agree__c = true; testCase.ContactId = testContact.Id; testCase.ProductId = testProduct.Id; insert testCase; Case testCase2 = new Case(); testCase2.RecordTypeId = L2CaseRecordType.Id; testCase2.Summary__c = 'Summary2'; testCase2.Description = 'Description2'; testCase2.Origin = 'Email2'; testCase2.Status = 'New2'; testCase2.I_Agree__c = true; testCase2.ContactId = testContact.Id; testCase2.ProductId = testProduct.Id; insert testCase2; Attachment att = new Attachment(); att.ParentId = testCase.Id; att.name = 'test'; att.body = blob.valueof('test'); insert att; Attachment attDup = new Attachment(); attDup.ParentId = testCase2.Id; attDup.name = att.name; attDup.body = att.body; List<Attachment> listatt = new List<Attachment>(); listatt.add(attDup); insert listatt; System.assertEquals(1, listatt.size()); Id idSelected; ApexPages.StandardController sc = new ApexPages.standardController(testCase); CopyAttachmentController cls = new CopyAttachmentController(sc); cls.Cancel(); cls.selectall = true; cls.displayAttTable = true; cls.matchingAttTable = true; CopyAttachmentController.AttachmentWrapper innerClass = new CopyAttachmentController.AttachmentWrapper(att); innerClass.selected = true; innerClass.att = att; List<CopyAttachmentController.AttachmentWrapper> attList = new List<CopyAttachmentController.AttachmentWrapper>(); //attList = null; system.currentPageReference().getParameters().put('idSelected', testCase.Id); System.assert(testCase.Id != null); List<CopyAttachmentController.AttachmentWrapper> listInnerClass = new List<CopyAttachmentController.AttachmentWrapper>(); listInnerClass.add(new CopyAttachmentController.AttachmentWrapper(attDup)); //List<string> s = new List<string>(); //s.add(att.name); //cls.matchingFiles = s; cls.SelectAttachments(); //System.assert(cls.matchingFiles.size()>0); } }Thanks
Also, never use seeAllData in your test unless you know 100% why you are using it. And given your test, there is no reason to use it.
[1] http://blog.deadlypenguin.com/blog/testing/strategies/