You need to sign in to do that
Don't have an account?
Ram S 49
Test Case for Trigger
Hi All,
Need help with below test case
@isTest
private class TestTimecardManager{
@testSetup static void setup()
{
Contact conct = new contact(FirstName='Test', LastName='TestLastName', Phone='4565465789');
insert conct;
Project__c prj = new Project__c(Name ='MyProject');
insert prj;
}
@isTest static void TestInserMethodValid()
{
//code to access contact and project objects
Assignment__c assign = new Assignment__c(Contact__c=conct.Title,Project__c='MyProject',Start_Date__c=Date.parse('01/01/2019'),End_Date__c=Date.parse('10/01/2019'));
}
}
As you see I need to access the contact and project object in TestInserMethodValid() method.
Need your help!.
Need help with below test case
@isTest
private class TestTimecardManager{
@testSetup static void setup()
{
Contact conct = new contact(FirstName='Test', LastName='TestLastName', Phone='4565465789');
insert conct;
Project__c prj = new Project__c(Name ='MyProject');
insert prj;
}
@isTest static void TestInserMethodValid()
{
//code to access contact and project objects
Assignment__c assign = new Assignment__c(Contact__c=conct.Title,Project__c='MyProject',Start_Date__c=Date.parse('01/01/2019'),End_Date__c=Date.parse('10/01/2019'));
}
}
As you see I need to access the contact and project object in TestInserMethodValid() method.
Need your help!.
The data created in @testSetup annotatted method acts as data available in the org. So, in order to access this data you will need to query the records in your TestInserMethodValid() method where you have written the comment - //code to access contact and project objects.
Hope this helps!
Thanks,
Pranav Sanvatsarkar.
Create 2 SOQL inside TestInserMethodValid method. One is for Contact, another - for Project. And then use it.