You need to sign in to do that
Don't have an account?
Guru 91
How to get test coverage for this method?
Hi All,
I am wring test class and i got only 25% code coverage and unable to achive test coverage for two methods
private static String appendWhere(String query,String whereCon ){
if(whereCon!=''){
String Id = whereCon.Split('\'')[1];
String str= whereCon;
integer tot= str.countMatches(' AND ');
system.debug('----------Test-------'+tot);
String acctIds =OV_BAUtility.getAcctIds(Id);
if(tot==2){
String andClause = (whereCon.contains('AND')?' AND '+whereCon.Split('AND')[1]+' AND '+whereCon.Split('AND')[2]:'');
query=query +' where '+whereCon.Split('=')[0]+' IN '+ acctIds +andClause;
}else{
String andClause = (whereCon.contains('AND')?' AND '+whereCon.Split('AND')[1]:'');
query=query +' where '+whereCon.Split('=')[0]+' IN '+ acctIds +andClause;
}
}
return query;
}
public static void setTotal(List<sobject> sObjectsList,String totalFields,lightningTableWrapper wrp){
List<String> total =totalFields.split(',');
system.debug('-----------------------------------------------tttttt-------------='+totalFields+'=----------'+sObjectsList+'total.size()---'+total.size());
Map<String,Decimal > totalmap= new Map<String,Decimal >();
if(total.size() > 1){
for(sObject obj :sObjectsList){
for(String t:total){
t=t.trim();
if(totalmap.containsKey(t)){
totalmap.put(t,totalmap.get(t)+(Decimal )obj.get(t));
}else{
totalmap.put(t,(Decimal )obj.get(t));
}
}
}
}
wrp.totalFields=totalmap;
}
Thanks
I am wring test class and i got only 25% code coverage and unable to achive test coverage for two methods
private static String appendWhere(String query,String whereCon ){
if(whereCon!=''){
String Id = whereCon.Split('\'')[1];
String str= whereCon;
integer tot= str.countMatches(' AND ');
system.debug('----------Test-------'+tot);
String acctIds =OV_BAUtility.getAcctIds(Id);
if(tot==2){
String andClause = (whereCon.contains('AND')?' AND '+whereCon.Split('AND')[1]+' AND '+whereCon.Split('AND')[2]:'');
query=query +' where '+whereCon.Split('=')[0]+' IN '+ acctIds +andClause;
}else{
String andClause = (whereCon.contains('AND')?' AND '+whereCon.Split('AND')[1]:'');
query=query +' where '+whereCon.Split('=')[0]+' IN '+ acctIds +andClause;
}
}
return query;
}
public static void setTotal(List<sobject> sObjectsList,String totalFields,lightningTableWrapper wrp){
List<String> total =totalFields.split(',');
system.debug('-----------------------------------------------tttttt-------------='+totalFields+'=----------'+sObjectsList+'total.size()---'+total.size());
Map<String,Decimal > totalmap= new Map<String,Decimal >();
if(total.size() > 1){
for(sObject obj :sObjectsList){
for(String t:total){
t=t.trim();
if(totalmap.containsKey(t)){
totalmap.put(t,totalmap.get(t)+(Decimal )obj.get(t));
}else{
totalmap.put(t,(Decimal )obj.get(t));
}
}
}
}
wrp.totalFields=totalmap;
}
Thanks
If you want to call private method to cover in test class, you should use "@TestVisible" just before the private method in your Apex.
Like this:
@TestVisible
private static String appendWhere(String query,String whereCon ){ ......... } If it helps you, mark your ans !!
Thanks
Niraj