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
subodh chaturvedi 17subodh chaturvedi 17 

My all Test Case Is passed But still getting 0% coverage

Test Class methods are passing But but when i am checking the Code Coverage it is giving me 0% coverage  & there is No is Color Code to show test class below  

@isTest
public class TestcardProgramsolparticipationcheck {
 public static testMethod void testRunAs() {
        // Setup test data
        // This code runs as the system user
        Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator']; 
        User u = new User(Alias = 'sysadm', Email='systemuser@testorg.com', 
            EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
            LocaleSidKey='en_US', ProfileId = p.Id, EmployeeNumber='12015',
            TimeZoneSidKey='America/Los_Angeles', UserName='csubodh@pscu.com');

        System.runAs(u) {
            // The following code runs as user 'u' 
            System.debug('Current User: ' + UserInfo.getUserName());
            System.debug('Current Profile: ' + UserInfo.getProfileId()); 
            
           
       }
   }
    Public static testMethod void method1()
     {
         List<Account> acc = new List<Account>();
         for(Integer i=0;i>=200;i++){
             Account a = new account(Name='XYZ'+i);
             acc.add(a);
         }
       
         List<Card_Program__c> cp =new List<Card_Program__c>();
         for(Integer i=0;i>=200;i++){
             Card_program__c cpr =new Card_Program__c(FI__c='12 Financial CU'+i,Card_Processor_Status__c='ACTIVE');
             cp.add(cpr);
         }
         test.starttest();
           Insert acc;
           Insert cp;
        
         List<Solution_Participation__c> spn= new List<Solution_Participation__c>();
         for(Integer i=0;i>=200;i++){
            Solution_Participation__c spr = new Solution_Participation__c(Card_Program__c='11800883',Active__c= true);
     }  
          List<Card_Program__c> cps =new List<Card_Program__c>();
         for(Integer i=0;i>=200;i++){
             Card_program__c cprs =new Card_Program__c(FI__c='12 Financial CU'+i,Card_Processor_Status__c='INACTIVE');
// FI__c is a lookup field from Account.

             cps.add(cprs);
         }
           Insert cps;
        
         List<Solution_Participation__c> sp= new List<Solution_Participation__c>();
         for(Integer i=0;i>=200;i++){
            Solution_Participation__c sprs = new Solution_Participation__c(Card_Program__c='11800884',Active__c= False);
         }
        test.stoptest();     
}
}

Actual Class --
Public class cardProgramsolparticipationcheck{

 Public Static Void checkFieldstatus(List<Card_Program__c> card){
    Map<id,Card_Program__c> programIds = new Map<id,Card_Program__c>();
    for(Card_Program__c cp : card){
    if(cp.card_processor_status__c != null){
        programIds.put(cp.id,cp);
      }
    }
    
    List<Solution_participation__c> updChildrecs = new List<Solution_participation__c>();
    List<Solution_participation__c> childrecs = [select id,Active__c,Card_Program__c from Solution_participation__c where Card_Program__c IN : programIds.keyset()];
    
    if(childrecs.size()>0){
      for(Solution_participation__c sp : childrecs){
        if(programIds.get(sp.Card_Program__c).card_processor_status__c == 'INACTIVE'){
           sp.Active__c = FALSE;
        }else {
           sp.Active__c = TRUE;
         }           
           updChildrecs.add(sp);
      }
      if(updChildrecs.size()>0){
          Update updChildrecs;
      }
     
    
    }



}
}
NagendraNagendra (Salesforce Developers) 
Hi Subodh,

Historically there were two ways to run test cases - Synchronous and Asynchronous. Only the async would actually track the coverage metrics.
In Winter '16 APIs and options were reintroduced to run the test in synchronous mode from the Developer Console.

This generally provided faster test execution for single test cases. There was a corresponding known issue that the synchronous test runs wouldn't provide coverage - Winter '16 - In Developer Console, running tests synchronously does not generate code coverage https://success.salesforce.com/issues_view?id=a1p30000000eMoyAAE.

It might be that this has regressed. I'd suggest explicitly running the tests asynchronously.

You can do this either with the Always Run Asynchronously option under the Test menu in the developer console or via the older UI /ui/setup/apex/ApexTestQueuePage.

Hope this helps.

Thanks,
Nagendra

 
Kartikeya GaurKartikeya Gaur
The reason you are not getting any code coverage is, you're not calling any medthod of your Actual class.
You must call method for coverage.


try something like this in the end of your test class:
cardProgramsolparticipationcheck.checkFieldstatus(cps);
OR
cardProgramsolparticipationcheck.checkFieldstatus(cp);

 
subodh chaturvedi 17subodh chaturvedi 17
Hi kartikeya ,
Now I am Getting Only only 40 % code Coverage, How i will cover it more than that 
Kartikeya GaurKartikeya Gaur
You have to test the functionality of your class. If you need further help you can share your org credentials with me.

Thanks!
subodh chaturvedi 17subodh chaturvedi 17
Hi Kartikeya,
Sry i can not share the credential's it will be a  security issue ,If you can help me here it would be great the apex Code is upfront. 
Kartikeya GaurKartikeya Gaur
Please mark above answer as best answer since it resolved the main problem of 0 % coverage.

Thanks.