You need to sign in to do that
Don't have an account?
Andrew Hoban 14
Compile Error on Test Class
Hi,
I have a test class that has a compile error when I try to save. I was wondering if anybody could help.
Many thanks
Class:
Test Class:
I have a test class that has a compile error when I try to save. I was wondering if anybody could help.
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(seeAllData = true) private class MatchReadyImageTest { private static void MatchReadyImage() { Match_Day_Check_List__c mdckl = new Match_Day_Check_List__c( name = 'Everton V West Ham United Goodison Park EPL 2013-05-12', Fixture__c = [select id from CS_Fixture__c limit 1].id, Match_Plan__c = [select id from Pre_Match__c limit 1].id); insert mdckl; System.assert((new MatchReadyImage).obj != null); } }
All Answers
Stack Trace: Class.MatchReadyImage.<init>: line 7, column 1
Class.MatchReadyImageTest.MatchReadyImage: line 12, column 1
You're using SeeAllData=true. This means your test class will see existing data on your org. It looks like the query in your constructor is returning multiple records because of this.
The best practice is to remove any dependency on existing data (Remove the SeeAllData=true annotation), and instead, create any records you may need in your unit test. In your case, you'll want to create records for CS_Fixture__c and Pre_Match__c prior to creating the "Match_Day_Check_List__c" record in your unit test.
James' answer is the way to go.
I have made an attempt at this, however the class is still failing. I am having trouble inserting the ID of both the CS_Fixture__c and Pre_Match__c (i think)
Thanks