我创建了一个测试类但是当它运行时我收到错误消息
“System.StringException:无效的id:Test”
“Stack Trace Class.MatchReadyImageTest.MatchReadyImage:第6行,第1列”
我做错了吗?
非常感谢
类别:
public class MatchReadyImage {
public Match_Day_Check_List__c obj {get; set; }
public MatchReadyImage(){
obj = [Select Id, Match_Day_Ready_Status__c From Match_Day_Check_List__c Where Name = 'Everton V West Ham United Goodison Park EPL 2013-05-12'];
}
}
测试类:
@isTest
public class MatchReadyImageTest {
static testMethod void MatchReadyImage() {
CS_Fixture__c fff = new CS_Fixture__c(Name = 'aaaaa', Fixture_Date__c = Date.Today(), CS_Season__c = 'Test', CS_Competition__c = 'Test', Football_Club__c = 'Test');
insert fff;
Pre_Match__c ppp = new Pre_Match__c();
insert ppp;
Match_Day_Check_List__c mmm = new Match_Day_Check_List__c(
Fixture__c = fff.id
,Match_Plan__c = ppp.id
,Name = 'Everton V West Ham United Goodison Park EPL 2013-05-12'
);
insert mmm;
Test.startTest();
MatchReadyImage con = new MatchReadyImage();
Test.stopTest();
System.assert(con.obj != null);
}
}
答案 0 :(得分:1)
这些字段CS_Season__c = 'Test', CS_Competition__c = 'Test', Football_Club__c = 'Test'
为relationship fields,因此您必须创建这些对象的相应记录,并使用这些记录的ID填充字段。