In my class one list of string is there which is get;set; type. i want to pass the value in test class how to do this

public class MYController(){

   Public list<string> selectedDelList{get;set;}

Test class

public class MYController_Test{
  static void testMethod unitTest(){
    MYController obj = new MYController();
    **obj.selectedDelList = 'test';**
    //above line is showing error
  • 1
    You aren't passing a list of Strings, just a String, in your test method. – Girbot Apr 12 '19 at 7:59

You have declared selectedDelList as List<String> and trying to assign a string to it which will give you compilation error.

This is how you should assign a value to List<String>

obj.selectedDelList = new List<String>();

Or you can do it during initialization as well as mentioned below

obj.selectedDelList = new List<String>{'test'};

If you have initialized the variable in your class's constructor, you can directly add the values to the list


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.