@isTest private class NewHighProductsOppControllerTest { @TestSetup static void setup(){ TestDataUtility.CreatePIPolicyConfigurations(new string[]{'Opportunity','SBG001','Contact'}); } @isTest static void test_method_one() { List rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer BS']; Account accIE = new Account( Name = '*', RecordTypeId = rectIE[0].Id, OwnerId = UserInfo.getUserId(), DivisionName__c='Customer BS', FacilityName__c='abc', PostCode__c = '123456' ); insert accIE; Contact con = new Contact(); con.LastName = 'test'; con.AccountId = accIE.Id; con.MobilePhone = 'MobilePhoneD__c'; con.OtherPhone = 'OtherPhoneD__c'; con.Fax = 'FaxD__c'; con.Email = 'EmailD__c@test.com'; con.Phone = 'PhoneD__c'; con.Title = 'TitleD__c'; con.Address1__c = 'Address1D__c'; con.Address2__c = 'Address2D__c'; con.Address3__c = 'Address3D__c'; con.Postcode__c = '100111'; con.ContactStatus__c = 'ContactStatusD__c'; con.CancelReason__c = 'CancelReasonD__c'; con.StatusD__c = 'Pass'; insert con; PriceBook2 pricebook =new PriceBook2( Name = 'BS', ProductSegment__c = 'BS', TradeType__c = 'Taxation', SalesChannel__c = 'direct', MachineParts__c = 'Machine' ); insert pricebook; PageReference page = new PageReference('/apex/NewHighProductsOpp?accid=' + accIE.Id + '&conId=' + con.Id); System.Test.setCurrentPage(page); NewHighProductsOppController controller = new NewHighProductsOppController(); controller.init(); controller.opp.Name = 'test opp 001'; controller.opp.TradeType__c = 'Taxation'; controller.opp.LeadSource = 'Others'; controller.opp.SalesChannel__c = 'direct'; controller.saveBtn(); //system.assertEquals(null,ApexPages.getMessages()[0].getDetail()); controller.saveBtnYes(); controller.saveBtnNo(); } }