0

Please help me in writing test class for below apex code,i wrote a test class which shows only 66% coverage,i am looking for 100%


public class PickListHandler {
    @AuraEnabled
    public static List<String> getLevel1(string strName) {   
        List<String> tempLst = new List<String>
        for(AggregateResult  ar : [select Level_1__c,COUNT(id) from Case_Type_Data__c  group by Level_1__c])
        {
            tempLst.add('Level 1 data is'+ar.get('Level_1__c'));

            return tempLst;
        } 
    }   
}

Here is test class

@isTest
public class testGetLevel1 {
    static testMethod void testGetLevel1() {
        List<String> s = PickListHandler.getLevel1('test');
        //System.assert(....);
    }
}
zaitsman
  • 8,984
  • 6
  • 47
  • 79
Carolyn Cordeiro
  • 1,525
  • 3
  • 11
  • 26
  • So this seems like the code you provided is incomplete. Why is there a `strName` argument to the method that is then unused? When you open code coverage report, which lines are red (not covered)? – zaitsman Jun 17 '20 at 00:01
  • got it thanks ,what you mean to say i get it now – Carolyn Cordeiro Jun 17 '20 at 00:09

1 Answers1

1

You need need to create test data for the object Case_Type_Data__c. If you don't create data, the logic inside for loop will not execute.

Priyanshu
  • 42
  • 1
  • 7