You need to sign in to do that
Don't have an account?
Mokshada
how to use assertequal for description field in apex test class
Hi,
I have apex code like
description = wrapperRec.accountName + '\'s ' + wrapperRec.shippingCity + ' location has shown a very high engagement with Siemens Energy\'s \"IP Address Targeting\" ' +wrapperRec.unitTypeFamily + ' ad.';
description = description + '\nWe advise our account manager to reach out to their customer contact and to gauge their interest in the product.';
description = description + '\n\nIn case more details are needed, please contact'+ accountBasedMarketingDetails.IP_Address_Contact__c;
description = description + '\n\n' + dt.format('MMMM') + ' '+d.day() +','+d.year();
prospect.Description__c = description;
and here IP_Address_Contact__c is a custom field on custom setting, I want that value should be populted and I want to check that in test class so I have written test function like ,
@isTest
public static void testCreateProspectsJabmoDescCheck() {
Account_Based_Marketing_Settings__c abmCustomSetting = new Account_Based_Marketing_Settings__c();
abmCustomSetting.Jabmo_Automation_Is_Active__c = true;
abmCustomSetting.Jabmo_Automation_Urgency__c = 'High Urgency';
abmCustomSetting.JABMO_CLICKS__c = 3;
abmCustomSetting.JABMO_CTR__c = 0.03;
abmCustomSetting.IP_Address_Contact__c ='Digi Sales at digi.sales@siemens-energy.com.';
insert abmCustomSetting;
Account acc = [Select id from account where name ='Taqa' limit 1];
String fullJson = '[{"Account Name": "Taqa","Unit Type Family": "FDS-IST-MGT-SGT-AGT-TCP","Country Code": "GB","Shipping City": "Brough","clicks": 5,"ctr": 0.0538677009},{"Account Name": "Taqa","Unit Type Family": "Cyber-IST-MGT-SGT-AGT-TCP-RCE","Country Code": "GB","Shipping City": "Brough","clicks": 6,"ctr": 0.0658761528}]';
Test.setMock(HttpCalloutMock.class, new RestMock(200,fullJson));
List<Prospect__c> prospectList = [Select id from Prospect__c where Account_Name__c =: acc.id];
System.assertEquals(0, prospectList.size());
Test.startTest();
CreateProspectsFromJabmo_Batch obj = new CreateProspectsFromJabmo_Batch();
DataBase.executeBatch(obj);
Test.stopTest();
prospectList = [Select id, Description__c from Prospect__c where Account_Name__c =: acc.id];
for(Prospect__c pro : prospectList){
System.assertEquals('In case more details are needed, please contactDigi Sales at digi.sales@siemens-energy.com.', pro.Description__c,'Description should match');
}
but getting error as, assertion failed
System.AssertException: Assertion Failed: Description should match: Expected: In case more details are needed, please contactDigi Sales at digi.sales@siemens-energy.com., Actual: Taqa's Brough location has shown a very high engagement with Siemens Energy's "IP Address Targeting" FDS-IST-MGT-SGT-AGT-TCP ad.
We advise our account manager to reach out to their customer contact and to gauge their interest in the product.
In case more details are needed, please contactDigi Sales at digi.sales@siemens-energy.com.
February 9,2023
can anyone help in writing correct assert statement for this?
Thanks,
I have apex code like
description = wrapperRec.accountName + '\'s ' + wrapperRec.shippingCity + ' location has shown a very high engagement with Siemens Energy\'s \"IP Address Targeting\" ' +wrapperRec.unitTypeFamily + ' ad.';
description = description + '\nWe advise our account manager to reach out to their customer contact and to gauge their interest in the product.';
description = description + '\n\nIn case more details are needed, please contact'+ accountBasedMarketingDetails.IP_Address_Contact__c;
description = description + '\n\n' + dt.format('MMMM') + ' '+d.day() +','+d.year();
prospect.Description__c = description;
and here IP_Address_Contact__c is a custom field on custom setting, I want that value should be populted and I want to check that in test class so I have written test function like ,
@isTest
public static void testCreateProspectsJabmoDescCheck() {
Account_Based_Marketing_Settings__c abmCustomSetting = new Account_Based_Marketing_Settings__c();
abmCustomSetting.Jabmo_Automation_Is_Active__c = true;
abmCustomSetting.Jabmo_Automation_Urgency__c = 'High Urgency';
abmCustomSetting.JABMO_CLICKS__c = 3;
abmCustomSetting.JABMO_CTR__c = 0.03;
abmCustomSetting.IP_Address_Contact__c ='Digi Sales at digi.sales@siemens-energy.com.';
insert abmCustomSetting;
Account acc = [Select id from account where name ='Taqa' limit 1];
String fullJson = '[{"Account Name": "Taqa","Unit Type Family": "FDS-IST-MGT-SGT-AGT-TCP","Country Code": "GB","Shipping City": "Brough","clicks": 5,"ctr": 0.0538677009},{"Account Name": "Taqa","Unit Type Family": "Cyber-IST-MGT-SGT-AGT-TCP-RCE","Country Code": "GB","Shipping City": "Brough","clicks": 6,"ctr": 0.0658761528}]';
Test.setMock(HttpCalloutMock.class, new RestMock(200,fullJson));
List<Prospect__c> prospectList = [Select id from Prospect__c where Account_Name__c =: acc.id];
System.assertEquals(0, prospectList.size());
Test.startTest();
CreateProspectsFromJabmo_Batch obj = new CreateProspectsFromJabmo_Batch();
DataBase.executeBatch(obj);
Test.stopTest();
prospectList = [Select id, Description__c from Prospect__c where Account_Name__c =: acc.id];
for(Prospect__c pro : prospectList){
System.assertEquals('In case more details are needed, please contactDigi Sales at digi.sales@siemens-energy.com.', pro.Description__c,'Description should match');
}
but getting error as, assertion failed
System.AssertException: Assertion Failed: Description should match: Expected: In case more details are needed, please contactDigi Sales at digi.sales@siemens-energy.com., Actual: Taqa's Brough location has shown a very high engagement with Siemens Energy's "IP Address Targeting" FDS-IST-MGT-SGT-AGT-TCP ad.
We advise our account manager to reach out to their customer contact and to gauge their interest in the product.
In case more details are needed, please contactDigi Sales at digi.sales@siemens-energy.com.
February 9,2023
can anyone help in writing correct assert statement for this?
Thanks,
As mentioned in the Error you have to add all the description variables and compare that with pro.Description__c.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
not able to do so, getting error again and again can you please help?
Thanks
I tried with sample apex class and test class and it is working as expected.
Apex Class:
Test Class:
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
can't we use contains in assertequal statement? If yes how can we do that
I hope we cannot do it. Only way would be like above.
Thanks,