You need to sign in to do that
Don't have an account?

Test Class to cover wrapper class
Hi All,
I am trying to cover wrapper class in calss. But it s not covering. I am sharing my class and test class.
Apex class
Test class:
I am trying to cover wrapper class in calss. But it s not covering. I am sharing my class and test class.
Apex class
public class accountCController { @AuraEnabled (cacheable=true) public static List<accWrapper> getNameValues(List<string> acname){ List<accWrapper> resultObject = new List<accWrapper>(); string query = 'SELECT Id,Name FROM account WHERE Name'; query+='=: acname'; List<SObject> lstResult = Database.query(query); for (SObject res : lstResult) { accWrapper obj = new accWrapper(); obj.testId = (String)res.get('Id'); obj.testName = (String)res.get('Name'); resultObject.add(obj); } return resultObject; } public class accWrapper{ @AuraEnabled public String testId; @AuraEnabled public String testName; } }
Test class:
@isTest public class accountController_Test { static testMethod void testName(){ List<string> strList = new List<string>(); strList.add('A'); strList.add('B'); accountCController.getNameValues(strList); } }
Its covering "getNameValues" method but it is not covering wrapper class. Please help me on this.
Thanks in advance
Regards,
Ramana
In the test class you need to build your test data. Since you are SOQLing the Account by the name so the query is returning 0 and not going into the For loop. Therefore wrapper class is not covering. Also it is a best practise to put the asset in the end, make your test legit.
Change your test class as follwoing
Please mark it the best if resolved
All Answers
Try reading the properties testId and testName from the result obtained from calling getNameValues(). Something like adding the following lines to test:
You could add some assert statements from those results.
I hope this helps
In the test class you need to build your test data. Since you are SOQLing the Account by the name so the query is returning 0 and not going into the For loop. Therefore wrapper class is not covering. Also it is a best practise to put the asset in the end, make your test legit.
Change your test class as follwoing
Please mark it the best if resolved