You need to sign in to do that
Don't have an account?
Rafael Franco Moreno 24
Test assert error
why I get this error? I think description example4 is not inserted but why? this is the method:
@IsTest
static void updateLeadsAndTasksTest(){
//update lead
Lead newLead = Build.aLead()
.withFirstName('rafa3')
.withLastName('franco3')
.withDescripcionPersonalizada('description example3')
.withTextoAuxiliar('aux text3')
.build();
insert newLead;
newLead.FirstName = 'rafa4';
newLead.LastName = 'franco4';
newLead.Descripcion_personalizada__c = 'description example4';
newLead.Texto_auxiliar__c = 'aux text4';
Test.startTest();
update newLead;
Test.stopTest();
List<Task> tasks = [
SELECT WhoId, Descripcion_personalizada__c, Texto_auxiliar__c
FROM Task
WHERE WhoId = :newLead.id];
for (Task task : tasks) {
system.debug(tasks);
system.debug('tasks');
}
// List<lead> leadQuery =[SELECT Descripcion_personalizada__c FROM Lead WHERE ]
System.assertEquals(newLead.Descripcion_personalizada__c = 'description example4' , String.valueOf(tasks.get(0).Descripcion_personalizada__c),'text');
System.assertEquals(newLead.Texto_auxiliar__c = 'aux text4' , String.valueOf(tasks.get(0)),'text');
//System.assertEquals(expected, actual, msg)
}
}
I am using TDD
@IsTest
static void updateLeadsAndTasksTest(){
//update lead
Lead newLead = Build.aLead()
.withFirstName('rafa3')
.withLastName('franco3')
.withDescripcionPersonalizada('description example3')
.withTextoAuxiliar('aux text3')
.build();
insert newLead;
newLead.FirstName = 'rafa4';
newLead.LastName = 'franco4';
newLead.Descripcion_personalizada__c = 'description example4';
newLead.Texto_auxiliar__c = 'aux text4';
Test.startTest();
update newLead;
Test.stopTest();
List<Task> tasks = [
SELECT WhoId, Descripcion_personalizada__c, Texto_auxiliar__c
FROM Task
WHERE WhoId = :newLead.id];
for (Task task : tasks) {
system.debug(tasks);
system.debug('tasks');
}
// List<lead> leadQuery =[SELECT Descripcion_personalizada__c FROM Lead WHERE ]
System.assertEquals(newLead.Descripcion_personalizada__c = 'description example4' , String.valueOf(tasks.get(0).Descripcion_personalizada__c),'text');
System.assertEquals(newLead.Texto_auxiliar__c = 'aux text4' , String.valueOf(tasks.get(0)),'text');
//System.assertEquals(expected, actual, msg)
}
}
I am using TDD
As per your code Lead should be update for description example4 ,
Please try below line :-
System.assertEquals(newLead.Descripcion_personalizada__c , 'description example4' );
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
All Answers
1. When you are tasks are getting inserted ? Is it in Lead insert or Lead Update... Please confirm...
2. Based on your screenshot the tasks are getting created at lead creation. Then If there is any update in lead details it's not reflecting in the related tasks.
In assert you comparing the task details with updated lead details. So please check is there any automation handling the task update or task creation for lead update.... If there is no code to handle this lead update on task then put assert before lead update... In case new task will be created for lead update then don't use tasks.get(0)) to compare and use the recent task to compare.
Thanks,
Maharajan.C
As per your code Lead should be update for description example4 ,
Please try below line :-
System.assertEquals(newLead.Descripcion_personalizada__c , 'description example4' );
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh