You need to sign in to do that
Don't have an account?
adrissel
Help with @isTest class!
I have a class that uses the StandardSetController and I honestly have no clue what to do to get some decent code coverage on it. I have written some basic parts of the test class, but can't figure out the rest. Can someone help me understand what needs to be done with these kinds of test classes.
Here is the controller:
Here is the current test class:
I don't know where to go from here.
Please help!
Thanks ahead of time!!
Here is the controller:
public with sharing class OutOfOffice { ApexPages.StandardSetController setCon; List<string> caseIds = new List<string>(); List<Case> caseList = new List<Case>(); public Case c; public Case getNewCase() { if(c == null){ c = new Case(); } return c; } public OutOfOffice (Apexpages.StandardSetController controller) { setCon = controller; caseIds = ApexPages.currentPage().getParameters().get('recs').split(',',-2); } public List<Case> getSelected() { caseList = [SELECT Subject,CaseNumber,Status FROM Case WHERE Id IN: caseIds]; return caseList; } public Pagereference updateCases(){ List<Case> updatedCases = new List<Case>(); for(Case cse : caseList){ cse.Out_Of_Office_Start__c = c.Out_Of_Office_Start__c; cse.Out_Of_Office_End__c = c.Out_Of_Office_End__c; cse.Out_Of_Office__c = c.Out_Of_Office__c; updatedCases.add(cse); } update updatedCases; return new Pagereference('/'+Case.getSObjectType().getDescribe().getKeyPrefix()+'?fcf='+ApexPages.currentPage().getParameters().get('retUrl')); } public Pagereference cancelUpdate(){ return new Pagereference('/'+Case.getSObjectType().getDescribe().getKeyPrefix()+'?fcf='+ApexPages.currentPage().getParameters().get('retUrl')); } }
Here is the current test class:
@isTest private class OutOfOfficeTest{ private static testmethod void testOutOfOffice() { // CREATE AND INSERT TEST CONTACT Contact con = new Contact (LastName = 'Smith', FirstName = 'Joe', Email = 'joesmith@test.com'); insert con; // CREATE START AND END DATES Date startDate = date.today(); Date endDate = startDate.addDays(1); // CREATE AND INSERT NEW CASE Case c = new Case( Out_Of_Office__c = true, Out_Of_Office_Start__c = startDate, Out_Of_Office_End__c = endDate, ContactId = con.Id ); insert c; // CREATE AND INSERT NEW EMAIL EmailMessage em = new EmailMessage( FromAddress = 'test@example.com', Incoming = true, ToAddress = 'test@gmail.com', Subject = 'Test email', TextBody = 'Hello', ParentId = c.Id ); insert em; // CREATE AND INSERT TEST CASE COMMENT CaseComment com = new CaseComment ( CommentBody = 'test', ParentId = c.Id, IsPublished = true ); insert com; } }
I don't know where to go from here.
Please help!
Thanks ahead of time!!
You have not created instance of controller.It should be something like
use system.assertEquals(expected result,actual result); to check data you inserted
These are the links to help you further.
https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
https://developer.salesforce.com/page/How_to_Write_Good_Unit_Tests
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_best_practices.htm
Regards
Nitesh
use system.assertEquals(expected result,actual result); to check data you inserted
These are the links to help you further.
https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
https://developer.salesforce.com/page/How_to_Write_Good_Unit_Tests
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_best_practices.htm
Regards
Nitesh
I get the following error:
It doesn't like the "con" variable being passed in the controller, apparently.
Did you get any solution for this test class. I have similar requiremnet and unbale to write test class. Please share the code if you have.
Thanks in advance.
Thanks,
Susheel Reddy