3

I have a class that only contains one map.

public with sharing class testController {
    public Map<String, User[]> mapName {get {.....return value;} set;}
}

I am unable to instantiate the class or call the method because it is not actually a method. How would I start testing something like this? Is there any documentation on testing with no methods to test? I can't find any documentation on something like this.

I have tried to manually create a user list, query a user list, instantiate the testController, and a few other variations.

8

You can still test it, because classes that have no defined constructors still have a default constructor. So, your unit test would look like this:

@isTest static void test() {
    testController c = new testController();
    System.assertNotEquals(null, c.mapName);
}
| improve this answer | |
  • ah great. I wasn't calling the assertNotEquals correctly. thank you! – Olivia Jan 4 '17 at 0:50
  • @Olivia Glad I could help! Sometimes its the little things we miss. – sfdcfox Jan 4 '17 at 0:52
  • how do i test a map on a trigger? @sfdcfox – Niveth Kumar Apr 8 '19 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.