+ Start a Discussion

Code coverage for the test class.



I have a test class written for my apex class. But i am not sure if correct. In the sandbox if RUN TEST for the class itself it says the following

Apex Test Result

Unfortunately you have a test failure there, so you wouldn't be able to deploy to production.


When you are creating your test opportunity, it is failing because you haven't supplied the Name field.


You'll need something like:



Opportunity opp= new Opportunity();
opp.Name='Test Opp';
opp.AccountId = acc.Id; 
opp.Placmnt_Start_Date_Arrive__c = Date.ValueOf('2/15/2011'); 
insert opp;


Try changing this an re-running your test.





Hello Bob,


Thank you so much for your response.


Yes i now actually did the change and added 


acc.Name = 'Test acc';


Test Failures



HFSendSurveyTestClass.SendSurvey988.0System.TypeException: Invalid date: 2/16/2011Class.HFSendSurveyTestClass.SendSurvey: line 25, column 45 External entry point





public class HFSendSurveyTestClass {

     static testMethod void SendSurvey()
      // Get the most recently created config object.
         Config_Object__c config = new Config_Object__c();
         config.Name = 'HostFamily_Survey';
         config.HFSurveyCode__c = 'HF1MoArv';
         config.Survey_Date__c = Date.today();
         config.SOQL_query__c = string.ValueOf('Select o.Id, o.Account.Id, o.AccountId, o.Account.Survey_Opp_Id__c, o.Account.Survey_Dt__c, o.Account.Survey_Code__c, o.Account.Name From Opportunity o where o.StageName= &#Active&# AND o.Placmnt_Start_Date_Arrive__c < Last_N_days :30 AND o.Placmnt_Start_Date_Arrive__c = Last_N_days :60');
         insert config;
         Account acc = new Account();
         acc.Name = 'Test acc';
         acc.Survey_Code__c = 'HF1MoArv';
         acc.Survey_Dt__c= Date.today();
         insert acc;  
         Opportunity opp= new Opportunity();
         opp.Name='Test Opp';
         opp.AccountId = acc.Id; 
         //Date plcdate = new Date(); 
         opp.Placmnt_Start_Date_Arrive__c = Date.valueof('02/10/2011');
         insert opp;
         HFSendSurveyClass hfsend = new HFSendSurveyClass();
        config = [Select HFSurveyCode__c, Survey_Date__C, SOQL_Query__C from Config_Object__C where Name =:config.Name];
        acc = [Select Survey_Code__c,Survey_Dt__c,Survey_Opp_Id__c from Account where id =:opp.AccountId ];


Can you please suggest Bob.


Hmm.  It seems to be having problems  with your opportunity date - not sure where it is getting 2/16/2011 from, but Date.valueof expects a different format - “yyyy-MM-dd HH:mm:ss”.


Its probably as easy to do:



    //Date plcdate = new Date(); 
    opp.Placmnt_Start_Date_Arrive__c = Date.newinstance(2011, 02, 10);
    insert opp;