+ Start a Discussion
embemb 

testing simple apex code: query and collect data in variable

Hello,

 

I am trying to make my first unit test code.

 

Here is the code. The result is ... 0%. How can i make it more efficient ?

 

Thank you!

Emmanuel

 

@isTest 
public class Requete_Calendrier_FF_TestClass2 {
    static testMethod void validateRequete_Calendrier_FF2() {

// Initialisation des variables
  String DataRessources='';
  String DataEvents;
  String testeurRessource;
  String testeurCategory;  
  String addrequete;
  //public String newpicklistvalue{get; set;}
  String monFiltre;   

    String qryString = 'Select nom__c, id__c, Tache__c, Ressource__c, Name, Id, Heure_Fin__c, Heure_Debut__c, Date__c, Categorie__c From Calendrier__c order by categorie__c asc,Ressource__c asc'; 
    
     for (Calendrier__c resultQuery : Database.query(qryString)){  
     if(testeurRessource==resultQuery.Ressource__c && testeurCategory==resultQuery.Categorie__c){}else{
    DataRessources+='{Id: "'+resultQuery.Ressource__c+'-'+resultQuery.Categorie__c+'", Name: "'+resultQuery.Ressource__c+'", Category : "'+resultQuery.Categorie__c+'", Type:"'+ resultQuery.Tache__c+'"},';
     }
     
     DataEvents+='{ResourceId: "'+resultQuery.Ressource__c+'-'+resultQuery.Categorie__c+'", Type : "'+resultQuery.Categorie__c+'", Title : "'+resultQuery.Tache__c+'", Ip : "'+resultQuery.Ressource__c+'",  NBapprenants : "10", StartDate : "'+resultQuery.Date__c+' '+resultQuery.Heure_Debut__c+'", EndDate : "'+resultQuery.Date__c+' '+resultQuery.Heure_Fin__c+'"},';
     
         
     testeurRessource=resultQuery.Ressource__c;
     testeurCategory=resultQuery.Categorie__c;
         
     }
  
    }
}
















IspitaIspita

Hi,

Though the exact cause analysis can be done if one goes through the code.

Yes it may happen that:-

  • There is an error in your code ~ run all tests and check the logs to see if any error has been encountered.
  • Also it might so happenthat your new code has added for conditional code with if-else and due to some reason some of the else or if statememts are not getting covered. 
  • You might have implemented condition for which you havent generated code or not created data to give due coverage.
  • The condition might be such that some conditions cannot be logically covered in the organizatgion's scenario.

 

Hope this helps...

NikuNiku

Hello emb

 

For which class you are writing the test method ???? I haven't Seen any Objet of Class .  

You are only firing the query  that will not work . Just create the object of the class for which you are writing the test method 

and call all the functions of the class by Instance of that class. 

 

1. Use eclipse to write the test method. 

2. Check the code coverage by eclipse.

3. Always use test.startTest() at starting of the test method. and ends with the Test.EndTest();

 

 

If you required more Information 

Please paste your Class code here.

 

Thanks Niks 

 

 

IspitaIspita

Also to add to whatever Niku has added , do try to check in salesforce or in ecllipse the the lasts of code which have not been covered , in that lies the answer of jacking up the coverage...

embemb

Thank you for your messages.

 

I will try your suggestions.

 

And will be back soon for explain what happened.

 

Emmanuel