You need to sign in to do that
Don't have an account?
Philippe - France
Trigger test Need Help
Hello,
The test for the trigger below is accept, but the coverage is 0%!
Surely, something escapes me as my eyes are tired :-(
Your new look will surely find the solution
Thank you in advance
Philippe
The trigger
And the Test :
The test for the trigger below is accept, but the coverage is 0%!
Surely, something escapes me as my eyes are tired :-(
Your new look will surely find the solution
Thank you in advance
Philippe
The trigger
trigger ContenantPrix on Pepiniere__c (after update) { List<ContenantRemise__c> subs = new List<ContenantRemise__c>(); // insertion remise for (Pepiniere__c PrixApartirde : Trigger.New) { subs.add(new ContenantRemise__c( id_feature_value__c = PrixApartirde.Remise_id_feature_value__c, id_feature__c = PrixApartirde.Remise_id_feature__c, Actif__c = true, Id__c = PrixApartirde.Remise_Id__c, Saison__c = PrixApartirde.ID ));} upsert subs Id__c; // insertion contenant for (Pepiniere__c Contenant : Trigger.New) { subs.add(new ContenantRemise__c( id_feature_value__c = Contenant.Contenant_id_feature_value__c, id_feature__c = Contenant.Contenant_id_feature__c, Actif__c = true, Id__c = Contenant.Contenant_Id__c, Saison__c = Contenant.ID ));} upsert subs Id__c; }
And the Test :
@istest private class TestContenantPrix { static TestMethod void TestContenantPrix() { Plante__c plante = new Plante__c(Name='Achillea millefolium',id_product__c ='32'); insert plante; Campagne__c campagne = new Campagne__c(name='2014'); insert campagne; Features__c fea = new Features__c(Name='Conteneur de 12 cm',id_feature__c='8',id_feature_value__c='37'); Insert fea; Features__c rem = new Features__c(Name='à partir de 3',id_feature__c='15',id_feature_value__c='46'); Insert rem; Pepiniere__c acc = new Pepiniere__c(Fiche__c=plante.id,Campagne__c=campagne.id,Contenant_pepi__c=fea.id,Prix_partir_de__c=rem.id); Insert acc; Catalogue__c cata = new Catalogue__c(Name='Achillea millefolium',fiche_de_la_plante__c=plante.id,production__c=acc.id,id_product__c='32'); insert cata; ContenantRemise__c testC1 = new ContenantRemise__c(Id__c ='32-8',Saison__c=acc.id,Actif__c = true,id_feature_value__c=acc.Contenant_id_feature_value__c,id_feature__c = acc.Contenant_id_feature__c); upsert testC1 Id__c; ContenantRemise__c testC2 = new ContenantRemise__c(Id__c ='32-15',Saison__c=acc.id,Actif__c = true,id_feature_value__c=acc.Remise_id_feature_value__c,id_feature__c = acc.Remise_id_feature__c); upsert testC2 Id__c; //pull the pepiniere info for that ContenantRemise ContenantRemise__c SecContenantRemise =[SELECT Id__c,Saison__c,Actif__c,id_feature_value__c,id_feature__c FROM ContenantRemise__c WHERE Id = :testC1.id]; ContenantRemise__c SecContRem =[SELECT Id__c,Saison__c,Actif__c,id_feature_value__c,id_feature__c FROM ContenantRemise__c WHERE Id = :testC2.id]; //verify that the insert updated by creating another ContenantRemise as in the trigger System.assert(SecContenantRemise.Id != null); System.assertEquals(SecContenantRemise.id_feature_value__c, testC1.id_feature_value__c); System.assertEquals(SecContenantRemise.id_feature_value__c, fea.id_feature_value_num__c); System.assertEquals(SecContenantRemise.Saison__c, acc.id); System.assert(SecContRem.Id != null); System.assertEquals(SecContRem.id_feature_value__c, testC2.id_feature_value__c); System.assertEquals(SecContRem.id_feature_value__c, rem.id_feature_value_num__c); System.assertEquals(SecContRem.Saison__c, acc.id); } }
Around line 30 try add this:
Regards,
Ana Catarina Brites
All Answers
I can be worng, but I don't see any update in the test.
The upsert is going to inset testC1 and testC2, I don't see a reson for it to do an update.
Or is it?
Regards,
Ana Catarina Brites
I modified the test with the insertion of two records so they can be updated ... but the coverage is always 0%
Around line 30 try add this:
Regards,
Ana Catarina Brites
I changed your code with just a id_product__c = 33 and
the coverage rate is now 100%
Certainly, there are many subtleties
Best regards
Philippe