· 8 years ago · Oct 11, 2017, 04:58 AM
1@isTest
2public class todaysBatchTests {
3
4
5 public static testMethod void testTodaysProcess(){
6 /***create test records***/
7 String query = 'SELECT id, name, domainName__c, name FROM Account WHERE ((name = \'gmail.com\' AND domainName__c = \'gmail.com\') OR'+
8 '(name = \'yahoo.com\' AND domainName__c = \'yahoo.com\') OR'+
9 '(name = \'hotmail.com\' AND domainName__c = \'hotmail.com\'))';
10 List<Account> dupeAccs = new List<Account>();
11 List<Contact> testCons = new List<Contact>();
12 List<Lead> testLeads = new List<Lead>();
13 List<Case> testCs = new List<Case>();
14 for(integer x=0;x<10;x++){
15 Account yahoo = new Account(name = 'yahoo.com', email_adress__c = 'jimmy'+x+'@yahoo.com');
16 Account gmail = new Account(name = 'gmail.com', email_adress__c = 'jimmy'+x+'@gmail.com');
17 Account hotmail = new Account(name = 'hotmail.com', email_adress__c = 'jimmy'+x+'@hotmail.com');
18 dupeAccs.add(yahoo);
19 dupeAccs.add(hotmail);
20 dupeAccs.add(gmail);
21 }
22
23 insert dupeAccs;
24 for(Account acc : dupeAccs){
25 For(integer x=0;x<20;x++){
26 Account testAcc = datafactory.testAccount(x);
27 insert testAcc;
28
29 testCons.add(datafactory.testcontact(x, testacc.id));
30 testLeads.add(datafactory.testLead(x,testacc.id));
31 testCs.add(datafactory.testCase(x, testacc.id));
32
33
34 }
35 }
36 insert testCons;
37 insert testleads;
38 insert testcs;
39
40 Account masterG = new Account(name = 'super duper master gmail.com', email_adress__c = 'super@gmail.com');
41 Account masterY = new Account(name = 'super duper master yahoo.com', email_adress__c = 'super@yahoo.com');
42 Account masterH = new Account(name = 'super duper master hotmail.com',email_adress__c = 'super@hotmail.com');
43 insert masterG;
44 insert masterY;
45 insert masterH;
46 /***test records created***/
47
48 //do our testing with a fresh set of limits
49 test.startTest();
50 //instantiate new batch class
51 todaysBatchProcess tbp = new todaysBatchProcess(query);
52 //execute batch process and store job id
53 Id batchid = database.executeBatch(tbp,50);
54 //spit out batchId to query job
55 system.debug(batchId);
56 test.stopTest();
57 system.assertEquals('Success', [SELECT status FROM AsyncApexJob WHERE id = :batchId].status);
58 }
59}