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
NaypersMclgxNaypersMclgx 

Test Method to Cover, help to cover this small function

Hi everyone!

 

I hope somebody can help me, I'd like to cover this function but I can't get it (not even a line)

 

Do you now what's going on?..  thanks for your time..

 

public with sharing class MyController {

	public List<SelectOption> getGenerateOptions(String value){
			
		value = (value == null) ? '' : value;
			
			List<SelectOption> elements = new List<SelectOption>();
			elements.add(new SelectOption(value, value));
			elements.add(new SelectOption('', '----'));
			
			for(Integer i=0; i < 11; i++){ 
				elements.add(new SelectOption('' + i, '' + i)); 
			}
			
			return elements;
		}

	// ...
}
	
 
static testmethod void myTest(){
	MyController test = new MyController();
	test.getGenerateOptions('5');
	
	// ...
}

 

 

 

Taiki YoshikawaTaiki Yoshikawa

Hi,

 

The test method must be in the class.

 

public with sharing class MyController {

    public List<SelectOption> getGenerateOptions(String value){
            
        value = (value == null) ? '' : value;
            
            List<SelectOption> elements = new List<SelectOption>();
            elements.add(new SelectOption(value, value));
            elements.add(new SelectOption('', '----'));
            
            for(Integer i=0; i < 11; i++){ 
                elements.add(new SelectOption('' + i, '' + i)); 
            }
            
            return elements;
        }

    // ...

    
 
    static testmethod void myTest(){
        MyController test = new MyController();
        test.getGenerateOptions('5');
    
        // ...
    }

}