function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dave ShulmanDave Shulman 

Testing at 0% coverage on deployment but 85% in sandbox

Hi all im trying to deploy a couple batch apex classes but they are not working on the change set.  The code works, the apex tests vailidate in the sandbox, the Code Coverage estimate is giving me about 85% for each, but when i deploy and Run Specified Test (the 2 test classes) i get 0% coverage.  why might this happen.  
@isTest
public class DeleteHalfYearSalesTest {
    public static testMethod void testSetup() {
        Test.startTest();
        List<Account> AccountList = new List<Account> (); 
        List<Sales_Data__c> SDList = new List<Sales_Data__c> (); 
        Account	Distributor = new Account(Name = 'Account Dist Test' ,
                                        RecordTypeID = '01280000000HeW4AAK');
        	insert Distributor;
        for (Integer a=0; a<5; a++) {
            Account acc = new Account(Name = 'Account ' + a,
                                      PDIid__c = 'PDI234' + a);
            AccountList.add(acc);
        }
        insert AccountList;
        for (Account ac : AccountList) {
            for (Integer s=0; s<5; s++) {
                Sales_Data__c sd = new Sales_Data__c (End_user__c = ac.Id,
                                                      Distributor__c = Distributor.ID,
                                                      Amount__c = 100,
                                                      Date__c = Date.today().addDays(-20),
                                                      Product__c = '01tC0000003HEvUIAW');
                SDList.add(sd);
            }
        }
        insert SDList;
        ID Var = SDList[0].ID;
                
        DeleteHalfYearSales d = new DeleteHalfYearSales();
        Database.executeBatch(d);

        Test.stopTest();
        
        Integer Actual = ([SELECT COUNT() FROM Sales_Data__c WHERE ID = :Var]);
        system.assertEquals(0, Actual);
        System.debug('Amount ' + Actual);
        
    }    
}

test class 2
 
@isTest
public class SalesDataBatchUpdateV3Test {
    public static testMethod void testSetup() {
        Test.startTest();
        List<Account> AccountList = new List<Account> (); 
        List<Sales_Data__c> SDList = new List<Sales_Data__c> (); 
        Account	Distributor = new Account(Name = 'Account Dist Test',
                                        RecordTypeID = '01280000000HeW4AAK');
        	insert Distributor;
        Account ParentAcc = new Account(Name = 'Account ParentAcc Test',
                                        RecordTypeID = '01280000000FzKfAAK',
                                        CMPNYid__c = 'CMPNY1234'); 
			insert ParentAcc;
        for (Integer a=0; a<5; a++) {
            Account acc = new Account(Name = 'Account ' + a,
                                      ParentID = ParentAcc.Id,
                                      CMPNYid__c = 'CMPNY234' + a);
            AccountList.add(acc);
        }
        insert AccountList;
        for (Account ac : AccountList) {
            for (Integer s=0; s<5; s++) {
                Sales_Data__c sd = new Sales_Data__c (End_user__c = ac.Id,
                                                      Distributor__c = Distributor.ID,
                                                      Amount__c = 100,
                                                      Date__c = Date.today().addDays(-20),
                                                      Product__c = '01tC0000003HEvUIAW');
                SDList.add(sd);
            }
        }
        Sales_Data__c Parentsd = new Sales_Data__c (End_user__c = ParentAcc.Id,
                                                    Distributor__c = Distributor.ID,
                                                    Amount__c = 100,
                                                    Date__c = Date.today().addDays(-20),
                                                    Product__c = '01tC0000003HEvUIAW');
        SDList.add(Parentsd);
        insert SDList;
        
        SalesDataBatchUpdateV3 t = new SalesDataBatchUpdateV3();
        Database.executeBatch(t);
        Test.stopTest();
        
        Account UpdatedTestChild = [SELECT ID, Sales_6_months__c, Acct_Primary_Distributor__c FROM Account WHERE ID = :AccountList[0].ID Limit 1];
        Account UpdatedTestParent = [SELECT ID, Rolling_12_months__c FROM Account WHERE ID = :ParentAcc.ID Limit 1];
        System.assertEquals(500, UpdatedTestChild.Sales_6_months__c);
        System.debug('Child Sales_6_months__c: 500' + ' Actual: ' + UpdatedTestChild.Sales_6_months__c);
        System.assertEquals(Distributor.id, UpdatedTestChild.Acct_Primary_Distributor__c);
        System.debug(Distributor.Id + ' : 01280000000HeW4AAK' + ' Actual: ' + UpdatedTestChild.Acct_Primary_Distributor__c);
        System.assertEquals(2600, UpdatedTestParent.Rolling_12_months__c);
        System.debug('Parent Rolling_12_months__c : 2600' + ' Actual: ' + UpdatedTestParent.Rolling_12_months__c);
    }
}


 
ShirishaShirisha (Salesforce Developers) 
Hi Dave,

Greetings!

I would suggest you to double check,if you see any warnings or error while validating/deploying the changesets.If there is no error then it could be because of the test data which might be causing the issue.

Also,I would suggest you to try with the RunSpecifiedTests including these two test classes to avoid running all the test classes.

If you are not able to narrow down the issue then please enable the debug logs while deploying/validating and check the code execution to figure out the root cause of the issue.

Reference:https://help.salesforce.com/apex/HTViewHelpDoc?id=code_add_users_debug_log.htm&language=en_us

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
Dave ShulmanDave Shulman
Hi Shirisha,  

Thanks so much for getting back to me, hope youre enjoying your saturday so far.  

When deploying i got no errors the below notice was the only notice i recieved on validate/deploy.  

User-added image

Also I ran only specified tests on this run, with only the test classes for these 2 running.  Must have to enable debugs and see whats going on i guess.  Thanks a bunch.