--------------------------------------------------------------------------------------------------------------------
Test Class for SOSL/
--------------------------------------------------------------------------------------------------------------------
@istest
private class SampleController_test {
private static Account acc1;
//set up data for each test method
static {
acc1 = new Account(Name='MyFatherCompany',Description='Produce stuff');
insert acc1;
System.assertEquals(1,[select count() from Account where Name = 'MyFatherCompany' ]);
}
static testMethod void test1(){
Test.startTest();
//Apply the setFixedSearchResults here
Id [] fixedSearchResults= new Id[1];
fixedSearchResults[0] =acc1.Id;
Test.setFixedSearchResults(fixedSearchResults);
SampleController obj = new SampleController();
obj.Strsearch=acc1.Name;
obj.search(); //This code is contain SOSL.
Test.stopTest();
}
}
---------------------------------------------------------------------------------------------------------------
Test Class for Batch apex:
---------------------------------------------------------------------------------------------------------------
@istest
public class MonthlyBill_batchClass_Test {
@testsetup
static void setup(){
list<job__c> myjob=new list<job__c>();
list<monthly_bill__c> mybills=new list<monthly_bill__c>();
for(integer i=0;i<10;i++){
job__c jobs=new job__c();
jobs.name='myjob' +i;
jobs.Job_Start_Date__c=date.newInstance(2019, 04, 01);
jobs.Job_End_Date__c=date.newInstance(2019, 06, 31);
myjob.add(jobs);
}
insert myjob;
for(job__c jo :[select id,name from job__c]){
Monthly_Bill__c bill=new Monthly_Bill__c();
bill.Name='all mybill';
bill.Bill_Start_Date__c=date.newInstance(2019, 04, 01);
bill.Bill_End_Date__c=date.newInstance(2019, 04, 31);
bill.job__c=jo.id;
mybills.add(bill);
}
insert mybills;
}
static testmethod void test(){
Test.startTest();
MonthlyBill_batchClass mb = new MonthlyBill_batchClass();
Id batchId = Database.executeBatch(mb);
Test.stopTest();
System.assertEquals(10, [select count() from Monthly_Bill__c where name = 'all mybill']);
}
}
Test Class for SOSL/
--------------------------------------------------------------------------------------------------------------------
@istest
private class SampleController_test {
private static Account acc1;
//set up data for each test method
static {
acc1 = new Account(Name='MyFatherCompany',Description='Produce stuff');
insert acc1;
System.assertEquals(1,[select count() from Account where Name = 'MyFatherCompany' ]);
}
static testMethod void test1(){
Test.startTest();
//Apply the setFixedSearchResults here
Id [] fixedSearchResults= new Id[1];
fixedSearchResults[0] =acc1.Id;
Test.setFixedSearchResults(fixedSearchResults);
SampleController obj = new SampleController();
obj.Strsearch=acc1.Name;
obj.search(); //This code is contain SOSL.
Test.stopTest();
}
}
---------------------------------------------------------------------------------------------------------------
Test Class for Batch apex:
---------------------------------------------------------------------------------------------------------------
@istest
public class MonthlyBill_batchClass_Test {
@testsetup
static void setup(){
list<job__c> myjob=new list<job__c>();
list<monthly_bill__c> mybills=new list<monthly_bill__c>();
for(integer i=0;i<10;i++){
job__c jobs=new job__c();
jobs.name='myjob' +i;
jobs.Job_Start_Date__c=date.newInstance(2019, 04, 01);
jobs.Job_End_Date__c=date.newInstance(2019, 06, 31);
myjob.add(jobs);
}
insert myjob;
for(job__c jo :[select id,name from job__c]){
Monthly_Bill__c bill=new Monthly_Bill__c();
bill.Name='all mybill';
bill.Bill_Start_Date__c=date.newInstance(2019, 04, 01);
bill.Bill_End_Date__c=date.newInstance(2019, 04, 31);
bill.job__c=jo.id;
mybills.add(bill);
}
insert mybills;
}
static testmethod void test(){
Test.startTest();
MonthlyBill_batchClass mb = new MonthlyBill_batchClass();
Id batchId = Database.executeBatch(mb);
Test.stopTest();
System.assertEquals(10, [select count() from Monthly_Bill__c where name = 'all mybill']);
}
}
No comments:
Post a Comment