You need to sign in to do that
Don't have an account?
emb
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;
}
}
}
Hi,
Though the exact cause analysis can be done if one goes through the code.
Yes it may happen that:-
Hope this helps...
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
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...
Thank you for your messages.
I will try your suggestions.
And will be back soon for explain what happened.
Emmanuel