+ Start a Discussion
Shwetal DesaiShwetal Desai 

How can i write Test Method for My this Trigger Code?

Hi,

I have a Trigger :

trigger UpdateSubTotalAndTotalTax on InventoryReceiptDetail__c (after insert, after update, after delete, after undelete, before update)
{
/* if(Trigger.isBefore && Trigger.isUpdate)
{
InventoryReceipt.UpdateReceivedCostInInventoryReceiptDetail(Trigger.new);
} */
if(Trigger.isDelete && Trigger.isAfter)
{
for(Integer i = 0; i < Trigger.old.size(); i++)
{
InventoryReceipt.UpdateSubTotalAndTotalTax(Trigger.old[i].ReceiptNo__c);
}
}
else if(Trigger.isInsert && Trigger.isAfter)
{
for(Integer i = 0; i < Trigger.new.size(); i++)
{
InventoryReceipt.UpdateSubTotalAndTotalTax(Trigger.new[i].ReceiptNo__c);
}
}
if(Trigger.isUpdate && Trigger.isAfter)
{
for(Integer i = 0; i < Trigger.new.size(); i++)
{
InventoryReceipt.UpdateInventoryStatusFromDetail(Trigger.new[i].ReceiptNo__c);
}
}
}

I dont know that how can i test this by writing Test method for this.

Please Help to solve this.

Thanks in advance

Shwetal Desai
jeffdonthemicjeffdonthemic

I would suggest you check out the following link at it has alot of great info:

 

Intro to Apex Testing

 

Jeff Douglas

Informa Plc

http://blog.jeffdouglas.com

Shwetal DesaiShwetal Desai
Thanks Jeff for replying,

I m sorry, i m not getting asnwer of my question from the link provided by you.

Can you explain me or clear me that how can i write / What should i write in test method for it?
jeffdonthemicjeffdonthemic

Shwetal,

 

You have to set up your test cases to test the outcomes for each of the logical branches in your trigger. If your code inserts new records, then you will have to query for those new records to ensure that they were created. If your code updates existing records, then you will have to query for those existing records and check that the values were update correctly.

 

Why don't you try posting some of your unit cases?

 

Jeff Douglas

Informa Plc

http://blog.jeffdouglas.com

hector.asp2hector.asp2
hi all

i am trying to write testMethod for below class but it's not working can any one help me out ?


public class DQIFileUpload{

String FileName= '';
Document d;
public DQIFileUpload(ApexPages.StandardController controller)
{
d = (Document)controller.getRecord();
d.folderid = UserInfo.getUserId();

}
public PageReference save()
{
try {
insert d;
FileName =d.Body.toString();
delete d;
return null;
}
catch(Exception e)
{
//Generic exception handling code here
return null;
}


}


public String getFileName()
{
return FileName;
}


static testMethod void ContactNullTest() {

test.starttest();
Document d;
Case testCase = new Case();
testCase.ContactId = null;
String FileName= '';
ApexPages.StandardController sc = new ApexPages.StandardController(testCase);
d = (Document)sc.getRecord();
d.folderid = UserInfo.getUserId();
insert d;
FileName =d.Body.toString();
delete d;
test.stoptest();




}

}