You need to sign in to do that
Don't have an account?
sumit 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;
}
}
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;
}
}
OppSt.oppstm();
This would call the method.
http://www.interactiveties.com/blog/2011/describe-picklist.php#.U320uPlmOo0