You need to sign in to do that
Don't have an account?
fiona gentry
How Do Include System.Assert in Existing @isTest class
Dear Pals,
This is the question on including System.Assert statements on existing test class which has 93% code coverage for Apex controller class
Here is the test class,need your help in writing system.debug statments in the below class
Here is controller class
Regards
Fiona
This is the question on including System.Assert statements on existing test class which has 93% code coverage for Apex controller class
Here is the test class,need your help in writing system.debug statments in the below class
@isTest public class ERT_MultiLevelSelectEditTest { @testSetup static void setup() { Case_Type_Data__c ct = new Case_Type_Data__c(); ct.Level_1__c = 'Test Level 1'; ct.Level_2__c = 'Test Level 2'; ct.Level_3__c = 'Test Level 3'; insert ct; } @isTest static void testGetLevel1() { Case cas = new Case(Status ='New', Priority = 'Medium', Origin = 'Email'); insert cas; ERT_Case_Type__c obj = new ERT_Case_Type__c (); obj.Level_1__c = 'Test Level 1'; obj.Level_2__c = 'Test Level 2'; obj.Level_3__c = 'Test Level 3'; obj.Case__c = cas.id; upsert obj; ERT_MultiLevelSelectEdit.getLevel1(obj.id); } @isTest static void testGetLevel2() { List<String> s = ERT_MultiLevelSelectEdit.getLevel2('Test Level 1'); } @isTest static void testGetLevel3() { List<String> s = ERT_MultiLevelSelectEdit.getLevel3('Test Level 1','Test Level 2'); } @isTest static void testsaveCaseType(){ Case cas = new Case(Status ='New', Priority = 'Medium', Origin = 'Email'); insert cas; ERT_Case_Type__c obj=new ERT_Case_Type__c(); string one='one'; string two='two'; string three='three'; test.startTest(); String testing=ERT_MultiLevelSelectEdit.savecasetype(one,two,three,cas.id); test.stopTest(); } }
Here is controller class
public class ERT_MultiLevelSelectEdit { @AuraEnabled public static List<LevelWrapper> getLevel1(string recID){ List<String> tempLst1 = new List<String>(); list<LevelWrapper> lstWrap=new list<LevelWrapper>(); list<ERT_Case_Type__c> lstertcase=new list<ERT_Case_Type__c>(); lstertcase=[select id,Level_1__c,Level_2__c,Level_3__c from ERT_Case_Type__c where id=:recID]; string strL1,strL2,strL3; if(lstertcase.size()>0){ strL1=lstertcase[0].Level_1__c; strL2=lstertcase[0].Level_2__c; strL3=lstertcase[0].Level_3__c; } for(AggregateResult ar : [select Level_1__c,COUNT(id) from Case_Type_Data__c group by Level_1__c]) { LevelWrapper obj= new LevelWrapper(); string strLev1=(string)ar.get('Level_1__c'); obj.strLevelType='recL1'; obj.strL1val=strLev1; if(strLev1==strL1) obj.isSelected=true; else obj.isSelected=false; lstWrap.add(obj); } for(string ar:getLevel2(strL1)){ if(strL1!=null){ LevelWrapper obj= new LevelWrapper(); string strLev2=(string)ar; obj.strLevelType='recL2'; obj.strL2val=strLev2; if(strLev2==strL2) obj.isSelected=true; else obj.isSelected=false; lstWrap.add(obj); } } for(string ar:getLevel3(strL1,strL2)){ if(strL2!=null){ LevelWrapper obj= new LevelWrapper(); string strLev2=(string)ar; obj.strLevelType='recL3'; obj.strL3val=strLev2; if(strLev2==strL3) obj.isSelected=true; else obj.isSelected=false; lstWrap.add(obj); } } System.debug(' wrapper '+lstWrap); return lstWrap; } @AuraEnabled public static List<String> getLevel2(string strName){ List<String> tempLst2 = new List<String>(); for(AggregateResult ar : [select Level_2__c,COUNT(id) from Case_Type_Data__c where Level_1__c=:strName group by Level_2__c]) { tempLst2.add(''+ar.get('Level_2__c')); } return tempLst2; } @AuraEnabled public static List<String> getLevel3(string strName1,string strName2){ List<String> tempLst3 = new List<String>(); for(AggregateResult ar : [select Level_3__c,COUNT(id) from Case_Type_Data__c where Level_1__c=:strName1 and Level_2__c=:strName2 group by Level_3__c]) { tempLst3.add(''+ar.get('Level_3__c')); } return tempLst3; } @AuraEnabled public static String savecasetype(string level1,string level2,string level3,string id){ string strMsg='successfull'; try{ ERT_Case_Type__c obj=new ERT_Case_Type__c(); System.debug('CASE = '+ Obj.Case__c); Obj.Level_1__c=level1; System.debug('Level1 = '+ Obj.Level_1__c); Obj.Level_2__c=level2; System.debug('Level2 = '+ Obj.Level_2__c); Obj.Level_3__c=level3; System.debug('Level3 = '+ Obj.Level_3__c); if(id.startsWithIgnoreCase('500')) Obj.Case__c = id; else obj.id=id; upsert obj; } catch(Exception ex){ strMsg='error'; } return strMsg; } public class LevelWrapper{ @AuraEnabled public string strLevelType{get;set;} @AuraEnabled public string strL1val{get;set;} @AuraEnabled public string strL2val{get;set;} @AuraEnabled public string strL3val{get;set;} @AuraEnabled public boolean isSelected{get;set;} } }
Regards
Fiona
copy and paste following test class with System.assert. Let me know if it help you and close your query by marking it as best so that it can help to others in future.
Thank you.
All Answers
copy and paste following test class with System.assert. Let me know if it help you and close your query by marking it as best so that it can help to others in future.
Thank you.
One place where you can use System.AssertEquals is in the testsaveCaseType Method
Let me know if this helps