You need to sign in to do that
Don't have an account?
Phantom
how to write Unit Test???
hi all!
please help me to guide me how to write unit test for this code below:
public List<SelectOption> TranmisionModes{ get { List<SelectOption> options = new List<SelectOption>(); options.add(new SelectOption('ALL', 'ALL')); Master_Data__c[] MDobjs = [Select m.Field_Description__c, Field_Code__c from Master_Data__c m where Field_Type__c='Transmission mode' and RecordTypeId= :rt_picklist.id]; for(Master_Data__c transmode: MDobjs) { options.add(new SelectOption(transmode.Field_Code__c, transmode.Field_Description__c )); } return options; } }
Hey
First you need to setup data in your unit test:
Create a test 'Master_data__c' record with test values and insert it.
Then instantiate the class that contains the code you've posted.
Next set the value of 'rt_picklist.id'.
Call 'getTranmisionModes' and assing it to a list of SelectOptions.
Loop through that list and assert the key's and value's for each SelectOption.
You should do this with valid and invalid data, just to make sure you've covered all scenarios.
Cheers,
Wes