You need to sign in to do that
Don't have an account?
Compass 1
Apex Test Class
I am new in Apex Development. I have written one Apex Class but need help to create the test unit for this class so I can deploy in production.
For reference find below the code of my Apex Class.
public class topprospectsqry{
public Opportunity[] getOpportunityList() {
Opportunity[] opps = [SELECT
name,
account.name,
Facility__c,
Scope_Of_Work__c,
Pricing_Type__c,
Revenue__c,
Contract_Award_Date__c,
FROM
Opportunity
where
Top_Prospect__c='Yes'
order by Revenue__c desc
LIMIT 20
];
return opps;
}
public pageReference generateReport() {
return Page.Thirdpage;
}
}
For reference find below the code of my Apex Class.
public class topprospectsqry{
public Opportunity[] getOpportunityList() {
Opportunity[] opps = [SELECT
name,
account.name,
Facility__c,
Scope_Of_Work__c,
Pricing_Type__c,
Revenue__c,
Contract_Award_Date__c,
FROM
Opportunity
where
Top_Prospect__c='Yes'
order by Revenue__c desc
LIMIT 20
];
return opps;
}
public pageReference generateReport() {
return Page.Thirdpage;
}
}
https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
http://www.sfdc99.com/2013/05/14/how-to-write-a-test-class/
For your code above
Error: Compile Error: expecting right curly bracket, found 'insert' at line 9 column 0
My test script,
-----------------
@isTest
private class topprospecttest{
// Load the test data
Account acc = new Account(Name='Test Acc');
insert acc;
// Load the test opportunities
List<Opportunity> opps = new List<Opportunity>();
for(Integer i=0;i<200;i++){
Opportunity opp = new Opportunity();
opp.AccountId = acc.Id;
opp.StageName = 'Prospecting';
opp.CloseDate = Date.today();
opp.Name = 'Test opp ' + i;
opps.add(opp);
}
insert opps;
// Test start here
Test.startTest();
topprospectsqry testcls = new topprospectsqry();
List<Opportunity> returned = testcls.getOpportunityList();
System.assertEquals(200,returned.size());
Test.stopTest();
}
----------------------------------------------------------------------------------------------------------
@isTest
private class topprospecttest{
static testMethod void verifyAccountDescriptionsWhereOverwritten(){
// Load the test data
Account acc = new Account();
acc.Name='Test of the Account1';
acc.type='Home';
insert acc;
// Load the test opportunities
List<Opportunity> opps = new List<Opportunity>();
for(Integer i=0;i<200;i++)
{
Opportunity opp = new Opportunity();
opp.AccountId = acc.Id;
opp.StageName = 'Prospecting';
opp.CloseDate = Date.today();
opp.Name = 'Test opp ' + i;
opps.add(opp);
}
insert opps;
// Test start here
Test.startTest();
topprospectsqry testcls = new topprospectsqry();
List<Opportunity> returned = testcls.getOpportunityList();
System.assertEquals(200,returned.size());
Test.stopTest();
}
}
------------------------------------------------------------------------------------------------------