You need to sign in to do that
Don't have an account?
Create simple Unit test class
Hi
i have created this simple trigger but i don't know how to do a test class.
please help me, it looks simple trigger and i suppose that is a simple test class.
trigger Block_Unblock_RejectionsTriger on QA_Order_Control__c (before insert,before update) {
for (QA_Order_Control__c objqaoc : Trigger.new)
{
if (objqaoc.Reject_team__c!=null )
{
objqaoc.Was_Created__c= true;
}
else {
objqaoc.Was_Created__c= false;
}
}
i have created this simple trigger but i don't know how to do a test class.
please help me, it looks simple trigger and i suppose that is a simple test class.
trigger Block_Unblock_RejectionsTriger on QA_Order_Control__c (before insert,before update) {
for (QA_Order_Control__c objqaoc : Trigger.new)
{
if (objqaoc.Reject_team__c!=null )
{
objqaoc.Was_Created__c= true;
}
else {
objqaoc.Was_Created__c= false;
}
}
All Answers
I am also knew to this salesforce codingJust try this code. Hope it will work!
@isTest (SeeAllData=true)
private class Block_Unblock_Rejections_Test {
static testMethod void myUnitTest() {
QA_Order_Control__c RtID = [SELECT Reject_team__c FROM QA_Order_Control__c where Reject_team__c !=null limit 1];
QA_Order_Control__c l = new QA_Order_Control__c( Reject_team__c=RtID.Reject_team__c //put some more fields ,mandatory once compulsory);
insert l;
system.assertequals(l.Was_Created__c ,'true');
}
}
Also to add in to the above Sample code, you cann also include conditions to test the other two conditions, in the test class. Hope you acn create it.So that 100% code is covered.
objqaoc.Was_Created__c= true;
objqaoc.Was_Created__c= false;
Also, you can find the best practices and some sample codde in the below link
>>https://developer.salesforce.com/page/How_to_Write_Good_Unit_Tests
Regards
Pramod
thanks so much for your support ramlakhan,Deepak and Pramod.
test class was successful .
best,
No worries, great that you were able to complete your test class
Regards
Pramod