Test Class Error Message "Invalid id: Test"

2.6k views Asked by At

I have created a test class however when it runs I am getting the error message

"System.StringException: Invalid id: Test"

"Stack Trace Class.MatchReadyImageTest.MatchReadyImage: line 6, column 1"

Is there something I have done wrong?

Many thanks

Class:

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'];
    }
}

Test Class:

@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);
    }
}
1

There are 1 answers

0
Pavel Slepiankou On

These fields CS_Season__c = 'Test', CS_Competition__c = 'Test', Football_Club__c = 'Test' are relationship fields, thus you have to create an appropriate records of these objects and populate fields with Ids of these records.