You need to sign in to do that
Don't have an account?
Code Coverage 0%, for triggers and shedulable classes
Dear All:
I'm having a big problem when I try to test some triggers and schedulable jobs, because when I run the test, the code coverage doesn't change and remains in 0%, in spite of I run the same test in the IDE and the coverage is the needed to deploy. I've been several days on it, any help or suggestion would be appreciated.
The code of one of my triggers is:
trigger NuevoRespaldoTrigger on Respaldos__c (before insert, before update) {
Validaciones validacion = new Validaciones();
QueriesConciliacion queries = new QueriesConciliacion();
List<Movimiento__c> movimientos = queries.consultarMovimientosPorConciliar();
List<Respaldos__c> respaldos = queries.consultarRespaldosPorConciliar();
List<Movimiento__c> movimientosPreConciliados = new List<Movimiento__c>();
Map<Id, List<Attachment>> adjuntosEnRespaldosPorConciliar = queries.adjuntos(respaldos);
Preconciliacion preconciliacion = new Preconciliacion();
MetodosUniversales metodos = new MetodosUniversales();
for(Respaldos__c respaldo: Trigger.new){
Boolean asignado = false;
RespaldoWrapper respaldoW = new RespaldoWrapper(respaldo, adjuntosEnRespaldosPorConciliar.get(respaldo.Id));
if(Trigger.isUpdate && Trigger.oldMap.get(respaldo.Id).Pre_Conciliado__c == respaldo.Pre_Conciliado__c){
System.debug('#### ' + asignado + ' ' + respaldoW.respaldo.Id);
for(Movimiento__c movimiento: movimientos){
if(!metodos.EnLista(movimiento, movimientosPreConciliados)){
if(!asignado && (respaldoW.adjuntos != null && respaldoW.adjuntos.size()>0) && validacion.comparar(movimiento, respaldoW.respaldo)){
Movimiento__c movimientoPreConciliado = (Movimiento__c)preconciliacion.preconciliar(movimiento, respaldo, 'Movimiento');
movimientosPreConciliados.add(movimientoPreConciliado);
asignado = true;
}
}
}
}
}
update movimientosPreConciliados;
}
And the code for the test class is:
@isTest(SeeAllData=true)
public class NuevoMovimientoRespaldoTriggerTest {
static testMethod void myUnitTest() {
Respaldos__c rq = [SELECT Id, Monto_Final__c FROM Respaldos__c WHERE Monto_Final__c = 1];
rq.Monto_Final__c = 100;
update rq;
}
}
Best Regards,
Daniela.
Daniela
Is the problem that your scheduled job is not executing (and thus showing no code coverage)?
A likely cause is that in order to test scheduled jobs, you need to wrap the 'event' that starts the scheduled job with a Test.startTest() and Test.stoptest(). See
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_scheduler.htm?SearchType=Stem
If that event is the update of rq, then ensure that you wrap that with Test.startTest() and Test.stopTest()
Hi Eric,
Thank you very much for your answer. I'm sorry I couldn't check this before.
As a matter of fact, I had already added the Test.startTest() and Test.stopTest() in the test code, but I didn't have success, I've always had 0% coverage running the test in the platform, but 84% coverage running it on the IDE :(.
I will continue trying.
Any other ideas??
Thanks again!