You need to sign in to do that
Don't have an account?
Admin IT 11
Apex batch test - issue with dependent classes
Hello,
I'm having trouble with apex tests.
As test functions are pretty repetitive, I wanted to code them in a seperated class and call them from my "actual" test class.
Problem is, when i'm developping in a sandbox, and coding tests for a batch class, I call a function from my "separated" test class, to setup my tests objects and everything works fine (tests are ok, code coverage too ...)
But when I try deploying through a Change Set the deployment status return a "Fatal Error" and 0% code coverage.
If I replace the call to my "external" test function, by the actual code of this function, it works during deployment.
see details within *lf_billingEvolutions_updateSubs_test* class code below.
During my deploy I upload all the classes needed.
In my case I have the following :
And the corresponding test class :
My "separated" test class with often used functions :
Can you help me having a separated class that contain all my function required to init test objects that I could call within any other specific test class ?
Do you see any problem with the code I provided, or the method detailled ?
Thanks in advance.
I'm having trouble with apex tests.
As test functions are pretty repetitive, I wanted to code them in a seperated class and call them from my "actual" test class.
Problem is, when i'm developping in a sandbox, and coding tests for a batch class, I call a function from my "separated" test class, to setup my tests objects and everything works fine (tests are ok, code coverage too ...)
But when I try deploying through a Change Set the deployment status return a "Fatal Error" and 0% code coverage.
If I replace the call to my "external" test function, by the actual code of this function, it works during deployment.
see details within *lf_billingEvolutions_updateSubs_test* class code below.
During my deploy I upload all the classes needed.
In my case I have the following :
global class lf_billingEvolutions_updateSubs implements Database.Batchable<sObject>, Database.Stateful { // instance member to retain state across transactions global Integer recordsProcessed = 0; global Database.QueryLocator start(Database.BatchableContext bc) { return Database.getQueryLocator( [my code] ); } global void execute(Database.BatchableContext bc, List<sofactoapp__Poste_d_abonnement__c> list_subLI_scope){ // process each batch of records List<sofactoapp__Poste_d_abonnement__c > subLI_to_update = new List<sofactoapp__Poste_d_abonnement__c >(); [my code] } global void finish(Database.BatchableContext bc){ } }
And the corresponding test class :
@isTest public class lf_billingEvolutions_updateSubs_test { @testSetup static void test_sub_update_setup() { // This works in sandbox but not during deployment : lf_testCommonFunctions.lf_billingEvolutions_updateSubs_initDataSet(); // This works in sandbox and during deployment : [code to create tests objects] // same that the code whithin the lf_billingEvolutions_updateSubs_initDataSet function... } static testmethod void test_sub_update() { Test.startTest(); lf_billingEvolutions_updateSubs batch_sub_update = new lf_billingEvolutions_updateSubs(); Id batchId = Database.executeBatch(batch_sub_update, 10); Test.stopTest(); // after the testing stops, assert records were updated properly System.assertEquals(1, 1); // just testing.. } }
My "separated" test class with often used functions :
@isTest public with sharing class lf_testCommonFunctions { public static void lf_billingEvolutions_updateSubs_initDataSet(){ [code to create tests objects] } }
Can you help me having a separated class that contain all my function required to init test objects that I could call within any other specific test class ?
Do you see any problem with the code I provided, or the method detailled ?
Thanks in advance.
please remove @istest annotation from lf_testCommonFunctions class and recheck. Let me know what happened.
Thanks,
Prosenjit