You need to sign in to do that
Don't have an account?
Rohith Kumar 98
How to attach test class to mocking framework?
I have test class
What is mocking framework and how to attach above test class to mocking framework?
@isTest public class PaymentOrderTriggerHandlerTest { @isTest public static void testUpdatePaymentContactInformationCheck(){ //Creating account Account account = new Account(Name = 'Test Account', Phone = '1234567890', BillingStreet = 'Test Billing Street', ShippingStreet = 'Test Shipping Street', ShippingPostalCode = '625014', ShippingState = 'Test State', ShippingCountry = 'Test country'); insert account; //Creating Payment Order with above account as lookup Payment_Order__c paymentOrder = new Payment_Order__c(Account__c = account.Id); insert paymentOrder; Test.startTest(); //Getting all test data String paymentOrderName = [SELECT Payee_Name__c FROM Payment_Order__c WHERE Account__c = :account.Id].Payee_Name__c; String paymentOrderPhone = [SELECT Phone_No__c FROM Payment_Order__c WHERE Account__c = :account.Id].Phone_No__c; String paymentOrderStreet1 = [SELECT Address_Street_1__c FROM Payment_Order__c WHERE Account__c = :account.Id].Address_Street_1__c; String paymentOrderStreet2 = [SELECT Address_Street_2__c FROM Payment_Order__c WHERE Account__c = :account.Id].Address_Street_2__c; String paymentOrderZip = [SELECT Zip__c FROM Payment_Order__c WHERE Account__c = :account.Id].Zip__c; String paymentOrderState = [SELECT State__c FROM Payment_Order__c WHERE Account__c = :account.Id].State__c; String paymentOrderCountry = [SELECT Country__c FROM Payment_Order__c WHERE Account__c = :account.Id].Country__c; System.assertEquals(account.Name, paymentOrderName); System.assertEquals(account.Phone, paymentOrderPhone); System.assertEquals(account.BillingStreet, paymentOrderStreet1); System.assertEquals(account.ShippingStreet, paymentOrderStreet2); System.assertEquals(account.ShippingPostalCode, paymentOrderZip); System.assertEquals(account.ShippingState, paymentOrderState); System.assertEquals(account.ShippingCountry, paymentOrderCountry); Test.stopTest(); } @isTest public static void testInsertAccountContactInformationCheck(){ //Creating Payment Order without lookup account Payment_Order__c paymentOrder = new Payment_Order__c(Payee_Name__c = 'Test Payment Order', Phone_No__c = '9876543210', Address_Street_1__c = 'Test Street 1', Address_Street_2__c = 'Test Street 2', Zip__c = '625014', State__c = 'Test State', Country__c = 'Test Country'); insert paymentOrder; //Getting Id, all data of account created by trigger ID accountID = [SELECT Account__c FROM Payment_Order__c WHERE Id = :paymentOrder.Id].Account__c; String accountName = [SELECT Name FROM Account WHERE Id = :accountId].Name; String accountPhone = [SELECT Phone FROM Account WHERE Id = :accountId].Phone; String accountBillingStreet = [SELECT BillingStreet FROM Account WHERE Id = :accountId].BillingStreet; String accountShippingStreet = [SELECT ShippingStreet FROM Account WHERE Id = :accountId].ShippingStreet; String accountZip = [SELECT ShippingPostalCode FROM Account WHERE Id = :accountId].ShippingPostalCode; String accountState = [SELECT ShippingState FROM Account WHERE Id = :accountId].ShippingState; String accountCountry = [SELECT ShippingCountry FROM Account WHERE Id = :accountId].ShippingCountry; Test.startTest(); System.assertEquals(paymentOrder.Payee_Name__c, accountName); System.assertEquals(paymentOrder.Phone_No__c, accountPhone); System.assertEquals(paymentOrder.Address_Street_1__c, accountBillingStreet); System.assertEquals(paymentOrder.Address_Street_2__c, accountShippingStreet); System.assertEquals(paymentOrder.Zip__c, accountZip); System.assertEquals(paymentOrder.State__c, accountState); System.assertEquals(paymentOrder.Country__c, accountCountry); Test.stopTest(); } @isTest public static void testSearchAndCreateAccountCheck(){ //Creating Account Account account = new Account(Name = 'Test Account', Phone = '1234567890', BillingStreet = 'Test Billing Street', ShippingStreet = 'Test Shipping Street', ShippingPostalCode = '625014', ShippingState = 'Test State', ShippingCountry = 'Test country'); insert account; //creating Payment Order Payment_Order__c paymentOrder = new Payment_Order__c(Payee_Name__c = 'Test Payment Order', Phone_No__c = '9876543210', Address_Street_1__c = 'Test Street 1', Address_Street_2__c = 'Test Street 2', Zip__c = '625014', State__c = 'Test State', Country__c = 'Test Country'); insert paymentOrder; //updating payment order to match above account data paymentOrder.Payee_Name__c = 'Test Account'; paymentOrder.Phone_No__c = '1234567890'; paymentOrder.Address_Street_1__c = 'Test Billing Street'; paymentOrder.Address_Street_2__c = 'Test Shipping Street'; paymentOrder.Zip__c = '625014'; paymentOrder.State__c = 'Test State'; paymentOrder.Country__c = 'Test Country'; update paymentOrder; //getting id of account associated with payment order ID paymentOrderAccountId = [SELECT Account__c FROM Payment_Order__c WHERE Id = :paymentOrder.Id].Account__c; Test.startTest(); System.assertEquals(account.Id, paymentOrderAccountId); //updating payment order to not match above account data paymentOrder.Phone_No__c = '7777777777'; update paymentOrder; //getting updated account lookup id paymentOrderAccountId = [SELECT Account__c FROM Payment_Order__c WHERE Id = :paymentOrder.Id].Account__c; System.assertNotEquals(account.Id, paymentOrderAccountId); Test.stopTest(); } @isTest public static void testUpdateStatusAndOwnerCheck(){ //Creating Payment Order with payment amount greater than 2000 Payment_Order__c paymentOrder = new Payment_Order__c(Payment_Amount__c = 2001); insert paymentOrder; //Getting status of payment order String status = [SELECT Status__c FROM Payment_Order__c WHERE Id = :paymentOrder.Id].Status__c; //getting Queue Id ID queueId = [SELECT Queue.Id FROM queuesobject WHERE queue.name='Payment Order Pending Approval'].Queue.Id; ID paymentOrderOwnerId = [Select OwnerId FROM Payment_Order__c WHERE Id = :paymentOrder.Id].OwnerId; Test.startTest(); System.assertEquals('Pending Approval', status); System.assertEquals(queueId, paymentOrderOwnerId); Test.stopTest(); } }
What is mocking framework and how to attach above test class to mocking framework?
Kindly find solution.
A mocking framework is used to create replacement objects. These objects can be Fakes, Stubs, and Mocks. In unit testing scenarios, developers use mocking frameworks to isolate dependencies. This allows for a quick, concise, and reliable way to ensure that the testing goes smoothly.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_stub_api.htm
https://automationchampion.com/tag/build-a-mocking-framework-with-the-apex-stub-api/
If you find your Solution than mark as this as a best answer.
Thanks and Regards
Suraj Tripathi.