I need to write test class for an account traversing trigger. What trigger does is say for my account record,it will fetch the parent account in top level.
Issue now is how do i pass parent id to my test class.This is what i have been trying so far and it has been failing
@isTest
private class TEST_GEN_FindGlobalUltimate
{
public static testMethod void createAccount()
{
list<account>parentlist = new list<account>();
list<account>childlist = new list<account>();
for (integer i = 0;i<2;i++)
{
parentlist.add(new account(name='Parent'+i));
}
for(integer i =0;i<2;i++);
{
}
insert(parentlist);
for( integer i = 0; i<2;i++)
{
system.debug('Parent is'+ parentlist[i].id);
childlist.add(new account(name = 'acc1'+i,parentid = parentlist[i].id));
}
insert(childlist);
}
}
Code that this is calling is listed below https://codereview.stackexchange.com/questions/29245/account-hierarchy-code-review
i think i know why its not working when i try to insert,since there is a static variable check on trigger to make sure it is not called twice.I need to update it by using isRunningTest. Is that the correct way to handle this?
Modifying my trigger class code saying
if(test.isrunningtest())
{ firstRun_GlobalUltimate = true; }
Is that a good practice?