You need to sign in to do that
Don't have an account?
Test coverage failed for Lookup fields in Apex class
Hi ,
for below code, Test coverage is failed and getting erros. can you pls check below my post :
Apex classs :
and below is my Test class :
@isTest
public class Test_PickListController {
static testMethod void insertValues() {
Resourse__c resource = new Resourse__c();
resource.Name='Test1';
resource.Job_type__c='Automation Engineer';
resource.Type_of__c= 'Bestshore';
resource.EngagementType__c = 'Fixed Price';
insert resource;
PickListController.getResource(resource.Id);
Skill_Management__c skillMgt = new Skill_Management__c();
skillMgt.Name='Java' ;
skillMgt.Skill_Category__c='Java' ;
skillMgt.Skills__c='Java' ;
insert skillMgt;
Skill_Management__c skillUpdate = [select Id,Name,Skill_Category__c,Skills__c from Skill_Management__c
where Id =:skillMgt.Id limit 1];
Skill__c ac = new Skill__c();
/* ac.Resource__c = resource.Id;
ac.Skill_Management__c = skillUpdate.id ;
insert ac;*/
PickListController pc = new PickListController();
PickListController.insertValues(ac,skillMgt.Id,resource.Id);
}
}
When i try to execute the Test class getting below and its coverage only 35% .Class.PickListController.insertValues: line 29, column 1 you pls check and help on this.
Class.Test_PickListController.insertValues: line 29, column 1.
can
Thanks
Try Below Code
All Answers
Try Below Test Class I've Made Changes Please Mark It As Best Answer If It Helps
Thank You!
When i try to exeucte the test class getting below error :
System.SObjectException: Field is not writeable: Skill__c.Resource__c
---
Class.PickListController.insertValues: line 33, column 1
Class.Test_PickListController.unitTest: line 26, column 1
@isTest
public class Test_PickListController {
@isTest
public static void unitTest() {
Resourse__c resource = new Resourse__c();
resource.Name='Test1';
resource.Job_type__c='Automation Engineer';
resource.Type_of__c= 'Bestshore';
resource.EngagementType__c = 'Fixed Price';
insert resource;
Skill_Management__c skillMgt = new Skill_Management__c();
skillMgt.Name='Java' ;
skillMgt.Skill_Category__c='Java' ;
skillMgt.Skills__c='Java' ;
insert skillMgt;
Skill__c ac = new Skill__c();
ac.Resource__c = resource; // Here getting error . This is lookup field
ac.Skill_Management__c = skillMgt.id ;
insert ac;
PickListController.getResource(resource.Id);
PickListController pc = new PickListController();
PickListController.insertValues(ac,resource.Id,skillMgt.Id);
}
}
Any ideas, how to fix this ....Thanks in advance
Comment That Line
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Resource__c]: [Resource__c]
Any clues do you have ?
Try Below Code
I understand ,for lookup no need to declare right..
Thank you