function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
prasanth kumarprasanth kumar 

error at simple test class for MAP program.

I am getting error at simple test class for map object.  At line 9:Variable is not visible: colors          please help me.
 
@istest

public class apex2test {

    @istest static void mytest()
    {
        apex2 ap=new apex2();
        
        system.assertequals(ap.colors.get('red'),'this is stop signal');
                            
    }
    
}






apex class:----------



public class apex2 {

    map<string,string> colors;
    
    public apex2()
    {
        colors=new map<string,string>();
        
        colors.put('red','this is stop signal');
        colors.put('green','this is start signal');
        colors.put('yellow','thisis slowdown signal');
    
        system.debug('the data of red is: '+colors.get('red'));
        system.debug('the count of colors is: '+colors.size());
        
    }
    
    
}

 
Best Answer chosen by prasanth kumar
Shrikant BagalShrikant Bagal
Please use following code:
 
@istest

public class apex2test {

    @istest static void mytest()
    {
        apex2 ap=new apex2();
        
        system.assertequals(ap.colors.get('red'),'this is stop signal');
                            
    }
    
}






apex class:----------



public class apex2 {

    public map<string,string> colors;
    
    public apex2()
    {
        colors=new map<string,string>();
        
        colors.put('red','this is stop signal');
        colors.put('green','this is start signal');
        colors.put('yellow','thisis slowdown signal');
    
        system.debug('the data of red is: '+colors.get('red'));
        system.debug('the count of colors is: '+colors.size());
        
    }
    
    
}

If its helps, please mark as best answer so it will help to other who will serve same problem.
​Thanks! 

All Answers

Shrikant BagalShrikant Bagal
Please use following code:
 
@istest

public class apex2test {

    @istest static void mytest()
    {
        apex2 ap=new apex2();
        
        system.assertequals(ap.colors.get('red'),'this is stop signal');
                            
    }
    
}






apex class:----------



public class apex2 {

    public map<string,string> colors;
    
    public apex2()
    {
        colors=new map<string,string>();
        
        colors.put('red','this is stop signal');
        colors.put('green','this is start signal');
        colors.put('yellow','thisis slowdown signal');
    
        system.debug('the data of red is: '+colors.get('red'));
        system.debug('the count of colors is: '+colors.size());
        
    }
    
    
}

If its helps, please mark as best answer so it will help to other who will serve same problem.
​Thanks! 
This was selected as the best answer
prasanth kumarprasanth kumar
thanks for help.  love u Shrikant