-
Notifications
You must be signed in to change notification settings - Fork 8
/
Test Data Factory
78 lines (63 loc) · 2.52 KB
/
Test Data Factory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
============step 1 Create test data factory========================
@isTest
public class TestDataFactory {
//Account object Test data
public static list<Account> CreateAccData(Integer NumAcc){
list<Account> lstAcc = new list<Account>();
for(Integer i=0; i<NumAcc; i++){
Account acc = new Account();
acc.Name='TestDataFactoryAccount'+i;
acc.Description='TestDataFactoryAccount'+i+'Description';
lstAcc.add(acc);
upsert lstAcc;
system.debug('@@@@ Test Data Factory Account: '+lstAcc);
}
return lstAcc;
}
//Lead Object Test Data
public static list<Lead> CreateLeadData(Integer NumLead){
list<Lead> lstLe = new list<Lead>();
try{
for(Integer i=0; i<=NumLead; i++){
Lead le = new Lead();
le.LastName='TestDataFacLead'+i;
le.Company='TestDataLe'+i+'C';
le.Status='Working - Contacted';
le.Fax='10101010';
lstLe.add(le);
upsert lstLe;
}
}catch(exception ex){
}
return lstLe;
}
//Opportunity Object Test Data
public static list<Opportunity> CreateOppData(Integer NumOpp){
list<Opportunity> lstOpp= new list<Opportunity>();
for(Integer i=0; i<=NumOpp; i++){
Opportunity opp = new Opportunity();
opp.Name='TestDataFacOpp'+i;
opp.StageName='Qualification';
opp.CloseDate=system.today();
opp.Multi_currecy__c='(USD 32,11.90)';
lstOpp.add(opp);
upsert lstOpp;
}
return lstOpp;
}
}
==========step 2 test class======================
a. For apex batch class
@isTest
public class Test_BatchOpportunityCurrency {
@isTest
public static void TestMethod1(){
list<Opportunity> lstOpp = new list<Opportunity>();
//Calling Test data factory's method to get data created in the class
lstOpp=TestDataFactory.CreateOppData(10);
test.startTest();
BatchOpportunityCurrency btOpCu= new BatchOpportunityCurrency();
Database.executebatch(btOpCu);
test.stopTest();
}
}