@isTest public class RenewaloppClassTest { public static ListOpportunities=new List(); @testsetup static void stup(){ Id newrectypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('New Business').getRecordTypeId(); Id RenewablerectypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Renewable Business').getRecordTypeId(); Opportunity op=new Opportunity(); op.Name='Test 1'; op.StageName='Closed Won'; op.CloseDate=System.today(); op.RecordTypeId=newrectypeId; Opportunities.add(op); Opportunity op1=new Opportunity(); op1.Name='Test 2'; op1.StageName='Closed Won'; op1.CloseDate=System.today(); op1.RecordTypeId=RenewablerectypeId; Opportunities.add(op1); insert Opportunities; } @isTest static void testRenewaloppMethod2() { // Create test data Account testAccount = new Account(Name = 'Test Account'); insert testAccount; Id newrectypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('New Business').getRecordTypeId(); Id RenewablerectypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Renewable Business').getRecordTypeId(); Opportunity testOpp1 = new Opportunity(); testOpp1.Name = 'Test Opp 1'; testOpp1.AccountId = testAccount.Id; testOpp1.CloseDate = System.today(); testOpp1.StageName = 'Prospecting'; testOpp1.RecordTypeId = newrectypeId; insert testOpp1; Opportunity testOpp2 = new Opportunity(); testOpp2.Id=testOpp1.Id; testOpp2.AccountId = testAccount.Id; testOpp2.CloseDate = System.today(); testOpp2.StageName = 'Closed Won'; testOpp2.RecordTypeId = RenewablerectypeId; Update testOpp2; Opportunity testOpp3 = new Opportunity(); testOpp3.Name='Test Opp 3'; testOpp3.CloseDate = System.today(); testOpp3.StageName = 'Closed Won'; testOpp3.RecordTypeId = RenewablerectypeId; Insert testOpp3; Opportunity testOpp4 = new Opportunity(); testOpp4.Id=testOpp3.Id; testOpp4.CloseDate = System.today(); testOpp4.StageName = 'Closed Won'; testOpp4.RecordTypeId = RenewablerectypeId; update testOpp4; Map nMap = new Map(); nMap.put(testOpp2.Id, testOpp2); nMap.put(testOpp4.Id, testOpp4); Map oMap = new Map(); oMap.put(testOpp1.Id, testOpp1); nMap.put(testOpp3.Id, testOpp3); // Call the method to test System.Test.startTest(); RenewaloppClass.RenewaloppMethod2(nMap, oMap); System.Test.stopTest(); } }