1

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;
  } 

}
1
  • 1
    Triggers - that respond to inserts, updates etc - can be made to run by code such as your test. Other Apex code - utility classes, controllers - need to be explicitly invoked from the test class as highfive shows.
    – Keith C
    May 22 '14 at 8:48
3

you are doing all but one step behind. In your test class, call your Apex class method.

static testMethod void myUnitTest() {
   // Your code
   List<string> testStringList = OppSt.oppstm();

   // Add some assertEquals as per your logic to test the method
} 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.