function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Brad007Brad007 

Code coverage for the test class.

Hi,

 

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
bob_buzzardbob_buzzard

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.StageName='Active';    
opp.Placmnt_Start_Date_Arrive__c = Date.ValueOf('2/15/2011'); 
insert opp;

 

Try changing this an re-running your test.

 

 

 

Brad007Brad007

Hello Bob,

 

Thank you so much for your response.

 

Yes i now actually did the change and added 

opp.Name

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();
         //acc.Survey_Opp_Id__c=opp.id;
         insert acc;  
        
         Opportunity opp= new Opportunity();
         opp.Name='Test Opp';
         opp.AccountId = acc.Id; 
         opp.StageName='Active';    
         //Date plcdate = new Date(); 
         opp.Placmnt_Start_Date_Arrive__c = Date.valueof('02/10/2011');
         insert opp;
         
         HFSendSurveyClass hfsend = new HFSendSurveyClass();
         hfsend.SendSurvey();
            
        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 ];
        
        System.assertEquals(config.HFSurveyCode__c,acc.Survey_Code__c);
        System.assertEquals(config.Survey_Date__C,acc.Survey_Dt__c);
        System.assertEquals(opp.Id,acc.Survey_Opp_Id__c);
        
     }
}

 

Can you please suggest Bob.

bob_buzzardbob_buzzard

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:

 

 

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