You need to sign in to do that
Don't have an account?
NickDev
Multiple steps in Utility Test Class?
Hi,
I am writing a Utility Test Class which can be called by many test methods.
Basically, the data I am creating as part of this has a lot of pre-requisit bits of data.
My question is, would you normally call one method inside each other method in the test class to generate each pre-requisit bit of data or would you just simply call every test method seperately from the main test class? - Thank you
Example one:
Example two:
I am writing a Utility Test Class which can be called by many test methods.
Basically, the data I am creating as part of this has a lot of pre-requisit bits of data.
My question is, would you normally call one method inside each other method in the test class to generate each pre-requisit bit of data or would you just simply call every test method seperately from the main test class? - Thank you
Example one:
@isTest(seeAllData=false) public class TestUtilityClass { public Account CreateAccount() { Account acct = new Account(); acct.Name = 'Joe Bloggs & Co'; insert acct; return acct; } public Contact CreateContact() { Account acct = CreateAccount(); Contact contact = new Contact(); contact.FirstName = 'Joe'; contact.LastName = 'Bloggs'; contact.AccountId = acct.Id; insert contact; return contact; }Then you call call it by
TestUtilityClass tcUtil = new TestUtilityClass(); Contact person = tcUtil.CreateContact();
Example two:
@isTest(seeAllData=false) public class TestUtilityClass { public Account CreateAccount() { Account acct = new Account(); acct.Name = 'Joe Bloggs & Co'; insert acct; return acct; } public Contact CreateContact(Account acct) { Contact contact = new Contact(); contact.FirstName = 'Joe'; contact.LastName = 'Bloggs'; contact.AccountId = acct.Id; insert contact; return contact; }Then you call call it by:
TestUtilityClass tcUtil = new TestUtilityClass(); Account acct = tcUtil.CreateAccount(); Contact person = tcUtil.CreateContact(acct);
Refer below links for more Info.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_utility_classes.htm
https://help.salesforce.com/articleView?id=Why-is-a-Test-class-evaluated-as-part-of-the-Organization-s-Code-Coverage&language=en_US&type=1
Let me know if this helps :)
Thanks!
Amit Singh.
No need to keep calling each method seperately... Thanks!