You need to sign in to do that
Don't have an account?
venkyyy
Test class not get 100%,
Hi can anybody give me test class for the following method.
-----------------
public PageReference addAllUsers(){
try{
integer cnt = 0;
String payload = '';
List<SkillUserSaveModel> users = new List<SkillUserSaveModel>();
List<string> agentIdList = new List<string>();
for (SkillUnassignedAgentModel userModel : SkillUnassignedUsers.resultSet.agents) {
if (cnt > 0){
payload += '&';
}
payload += 'agents[' + string.valueOf(cnt) + '][agentId]:' + userModel.agentId;
payload += '&agents[' + string.valueOf(cnt) + '][isActive]:' + 'true';
payload += '&agents[' + string.valueOf(cnt) + '][proficiency]:' + getProficiencyId('Medium');
cnt++;
}
payload = EncodingUtil.urlEncode(payload, 'UTF-8');
payload = payload.replace('%3A', '=');
payload = payload.replace('%26', '&');
System.debug('addAllUsers payLoad :: ' + payload);
String result = ApiClient.addSkillUsers(skillId, payload);
SkillAssignedUsers = ApiClient.getSkillAgents(skillId);
SkillUnassignedUsers = ApiClient.getSkillUnassignedAgents(skillId);
}
catch(ApiResponseException apiEx ) {
IsInvalid = true;
ApexPages.Message errorMsg = new ApexPages.Message(ApexPages.Severity.ERROR, apiEx.ErrorDescription);
ApexPages.addMessage(errorMsg);
}
catch(Exception e) {
System.debug(logginglevel.ERROR, 'Error in addAllUsers:' + e.getMessage());
IsInvalid= true;
ApexPages.Message errorMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Error occurred. ' + e.getMessage());
ApexPages.addMessage(errorMsg);
}
return null;
}
-----------------------------
-----------------
public PageReference addAllUsers(){
try{
integer cnt = 0;
String payload = '';
List<SkillUserSaveModel> users = new List<SkillUserSaveModel>();
List<string> agentIdList = new List<string>();
for (SkillUnassignedAgentModel userModel : SkillUnassignedUsers.resultSet.agents) {
if (cnt > 0){
payload += '&';
}
payload += 'agents[' + string.valueOf(cnt) + '][agentId]:' + userModel.agentId;
payload += '&agents[' + string.valueOf(cnt) + '][isActive]:' + 'true';
payload += '&agents[' + string.valueOf(cnt) + '][proficiency]:' + getProficiencyId('Medium');
cnt++;
}
payload = EncodingUtil.urlEncode(payload, 'UTF-8');
payload = payload.replace('%3A', '=');
payload = payload.replace('%26', '&');
System.debug('addAllUsers payLoad :: ' + payload);
String result = ApiClient.addSkillUsers(skillId, payload);
SkillAssignedUsers = ApiClient.getSkillAgents(skillId);
SkillUnassignedUsers = ApiClient.getSkillUnassignedAgents(skillId);
}
catch(ApiResponseException apiEx ) {
IsInvalid = true;
ApexPages.Message errorMsg = new ApexPages.Message(ApexPages.Severity.ERROR, apiEx.ErrorDescription);
ApexPages.addMessage(errorMsg);
}
catch(Exception e) {
System.debug(logginglevel.ERROR, 'Error in addAllUsers:' + e.getMessage());
IsInvalid= true;
ApexPages.Message errorMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Error occurred. ' + e.getMessage());
ApexPages.addMessage(errorMsg);
}
return null;
}
-----------------------------
Each test should follow the following structure:
- Setup of test data. This includes creation of any data needed by your class. Account, Contacts etc
- Starting the test. This is calling Test.startTest() to reset the governor limits
- Calling your class / method
- Stopping the test.This is calling Test.stopTest() to reset the governor limits and allow for any async jobs to finish
- Asserting that your changes have worked
- If you have inserted/updated/deleted data, you need to query for the updates
- Run System.assert, System.assertEquals, System.assertNotEquals to verify that you got the correct data back
If you have any specific problems with your tests, feel free to create a new post or update this post with the part of the class you are trying to test and your current test method, and you will more likely get a better response then asking for someone to essentially write an entire test class for you.NOTE: Please use the "Add a code sample" button (icon <>) when adding code to increase readability and make it so your code can be easily referenced.
[1] http://www.sfdc99.com/2013/05/14/how-to-write-a-test-class/
[2] http://pcon.github.io/presentations/testing/
[3] http://blog.deadlypenguin.com/blog/2014/07/23/intro-to-apex-auto-converting-leads-in-a-trigger/
[4] http://blog.deadlypenguin.com/blog/testing/strategies/