Skip to main content
1 of 2
sumit
  • 479
  • 1
  • 9
  • 25

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;
  } 
            
}
sumit
  • 479
  • 1
  • 9
  • 25