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)
       return Opp; 

Test class:

private class TestOpportunityStageUtility {

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


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