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
sumit pawarsumit pawar 

how to write test class for below apex class?

I have created a code to get picklistfield dynamically and its values...
now i want to create test class for it i have created test class but its seems wrong...
Please help to create test class for belo apex class...

Apex class:

public with sharing class OppSt {

public List<string> Opp{get;set;}

public static list<string> oppstm(){
  list<string> Opp = new list<string>();
  Schema.DescribeFieldResult fieldResult = Opportunity.StageName.getDescribe();
  SObjectType accountType = Schema.getGlobalDescribe().get('Opportunity');
  Map<String,Schema.SObjectField> mfields = accountType.getDescribe().fields.getMap();
 
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry f : ple)
        {
      Opp.add(f.getLabel());
       }
       system.debug('============='+Opp);
       return Opp; 
}
          
}

Test class:

@isTest
private class TestOpportunityStageUtility {

    static testMethod void myUnitTest() {
       
  Opportunity o = new Opportunity ();
  o.StageName = 'abc';
  insert o;
    }
   
}
Vinit_KumarVinit_Kumar
Try calling your method in Test class.Put this line in your test class :-

OppSt.oppstm();

This would call the method.
Ramu_SFDCRamu_SFDC
The following article has an example of how to fetch the picklist fields and how to test it

http://www.interactiveties.com/blog/2011/describe-picklist.php#.U320uPlmOo0