+ Start a Discussion
kirankumarreddy punurukirankumarreddy punuru 

how to cover this line in test class

Hi ,
I am having one condtion in trigger like :
if(trigger.isUpdate && trigger.isAfter)
{
code;
}
 how to satisfy the above if condition to cover the code inside if condition .

Regards,
Kiran
 
Best Answer chosen by kirankumarreddy punuru
AshlekhAshlekh
Hi,

Just write a test class and create a record in test class and then update that reocrd.

For eg:
 
@isTest
Private class TestClassAccountTrigger{

static testMethod void myTest(){
   Account a = new Account(name='Test');
   insert a;
   Test.StartTest();
   a.name = 'Test 2';
   update a;
   Test.StopTest();
 }
}

-Thanks
Ashlekh Gera

All Answers

AshlekhAshlekh
Hi,

Just write a test class and create a record in test class and then update that reocrd.

For eg:
 
@isTest
Private class TestClassAccountTrigger{

static testMethod void myTest(){
   Account a = new Account(name='Test');
   insert a;
   Test.StartTest();
   a.name = 'Test 2';
   update a;
   Test.StopTest();
 }
}

-Thanks
Ashlekh Gera
This was selected as the best answer
kirankumarreddy punurukirankumarreddy punuru
Thanks Ashlekh Gera