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
prazonprazon 

Help required : testcoverage is coming 0 inspite of test method

Hi,

 

Please look into the class where test coverage is coming zero inspite of  testmethod

 

public with sharing class Account_Flag_Status_Controller {
    
    public Id AccountId{get;set;}
    public List<Flag_Reporter__c> flagReport{get;set;}
    public Account_Flag_Status_Controller(ApexPages.StandardController controller) {
        AccountId= ApexPages.currentPage().getParameters().get('id');
        flagReport = new List<Flag_Reporter__c>();
    }
    
    public class FlagColors{
        public String overallStatus{get;set;}
        public String leadFlag{get;set;}
        public String creditFlag{get;set;}  
        public String venueFlag{get;set;} 
        public String companyFlag{get;set;}
        public String editorial{get;set;}
        public String websiteFlag{get;set;}
        public String msFlag{get;set;}
        public String pmFlag{get;set;}
        public String escalationFlag{get;set;}
        public String FlagComments{get;set;}
        public String OverallComments{get;set;}
    }
    
    public Pagereference back() {
        Pagereference contractPage = new Pagereference('/' + AccountId);
        return contractPage;
    }
    
    public FlagColors colorSetter{
    get{
    
        FlagColors flagColors = new FlagColors();
        try{
            flagReport = [Select Overall_Status__c, LeadQualityFlag__c, CreditCheckFlag__c,Venue__c, CompanyAgeFlag__c,Flag_for_Editorial__c, WebsiteFlag__c, Overall_Mystery_Shopping__c,Overall_PM_Assessment__c,Overall_Escalation__c, Flag_comments__c, Overall_comments__c  from Flag_Reporter__c Where Account_Flag__c=:AccountId LIMIT 1];
        }catch(Exception ex){
            flagColors.overallStatus = 'Green.png';
            flagColors.leadFlag = 'Green.png';
            flagColors.creditFlag= 'Green.png';
            flagColors.venueFlag= 'Green.png';
            flagColors.companyFlag= 'Green.png';
            flagColors.editorial= 'Green.png';
            flagColors.websiteFlag= 'Green.png';
            flagColors.msFlag= 'Green.png';
            flagColors.pmFlag= 'Green.png';
            flagColors.escalationFlag= 'Green.png';
            
            return flagColors;
            
        }
        if(flagReport[0].Overall_Status__c == 'RED')
            flagColors.overallStatus = 'Red.png';
        else if(flagReport[0].Overall_Status__c == 'GREEN')
            flagColors.overallStatus = 'Green.png';
        else if(flagReport[0].Overall_Status__c == 'YELLOW')
            flagColors.overallStatus = 'Yellow.png';
            
        if(flagReport[0].LeadQualityFlag__c == 'RED')
            flagColors.leadFlag = 'Red.png';
        else if(flagReport[0].LeadQualityFlag__c == 'GREEN')
            flagColors.leadFlag = 'Green.png';
        else if(flagReport[0].LeadQualityFlag__c == 'YELLOW')
            flagColors.leadFlag = 'Yellow.png';
            
        if(flagReport[0].CreditCheckFlag__c == 'RED')
            flagColors.creditFlag = 'Red.png';
        else if(flagReport[0].CreditCheckFlag__c == 'GREEN')
            flagColors.creditFlag = 'Green.png';
        else if(flagReport[0].CreditCheckFlag__c == 'YELLOW')
            flagColors.creditFlag = 'Yellow.png';
            
        if(flagReport[0].Venue__c == 'RED')
            flagColors.venueFlag = 'Red.png';
        else if(flagReport[0].Venue__c == 'GREEN')
            flagColors.venueFlag = 'Green.png';
        else if(flagReport[0].Venue__c == 'YELLOW')
            flagColors.venueFlag = 'Yellow.png';
        
        if(flagReport[0].CompanyAgeFlag__c == 'RED')
            flagColors.companyFlag = 'Red.png';
        else if(flagReport[0].CompanyAgeFlag__c == 'GREEN')
            flagColors.companyFlag = 'Green.png';
        else if(flagReport[0].CompanyAgeFlag__c == 'YELLOW')
            flagColors.companyFlag = 'Yellow.png';
        
        
        if(flagReport[0].Flag_for_Editorial__c == 'RED')
            flagColors.editorial = 'Red.png';
        else if(flagReport[0].Flag_for_Editorial__c == 'GREEN')
            flagColors.editorial= 'Green.png';
        else if(flagReport[0].Flag_for_Editorial__c == 'YELLOW')
            flagColors.editorial= 'Yellow.png';
                        
        if(flagReport[0].WebsiteFlag__c == 'RED')
            flagColors.websiteFlag = 'Red.png';
        else if(flagReport[0].WebsiteFlag__c == 'GREEN')
            flagColors.websiteFlag = 'Green.png';
        else if(flagReport[0].WebsiteFlag__c == 'YELLOW')
            flagColors.websiteFlag = 'Yellow.png';
                        
        if(flagReport[0].Overall_Mystery_Shopping__c == 'RED')
            flagColors.msFlag = 'Red.png';
        else if(flagReport[0].Overall_Mystery_Shopping__c == 'GREEN')
            flagColors.msFlag = 'Green.png';
        else if(flagReport[0].Overall_Mystery_Shopping__c == 'YELLOW')
            flagColors.msFlag = 'Yellow.png';
        
        if(flagReport[0].Overall_PM_Assessment__c == 'RED')
            flagColors.pmFlag = 'Red.png';
        else if(flagReport[0].Overall_PM_Assessment__c == 'GREEN')
            flagColors.pmFlag = 'Green.png';
        else if(flagReport[0].Overall_PM_Assessment__c == 'YELLOW')
            flagColors.pmFlag = 'Yellow.png';                
                        
          if(flagReport[0].Overall_Escalation__c == 'RED')
            flagColors.escalationFlag = 'Red.png';
        else if(flagReport[0].Overall_Escalation__c == 'GREEN')
            flagColors.escalationFlag= 'Green.png';
        else if(flagReport[0].Overall_Escalation__c == 'YELLOW')
            flagColors.escalationFlag = 'Yellow.png';
         
         if(flagReport[0].Flag_comments__c != NULL)
             flagColors.FlagComments = flagReport[0].Flag_comments__c;
         else
             flagColors.FlagComments = 'No comment so far';
         
         if(flagReport[0].Overall_comments__c != NULL)
             flagColors.OverallComments = flagReport[0].Overall_comments__c;
         else
             flagColors.OverallComments = 'No comment so far';
                  
        return flagColors ;
    }
    
    
    }
    static testMethod void testWithFlag() {
    
        Account flagTestAccount = new Account(Name='Flag Test Account',Actual_Physical_Country__c='UK',BillingCountry='UK',Partner_Reviews__c='1');
        insert flagTestAccount;
        
        Account flagTestAccount1 = new Account(Name='Flag Test Account',Actual_Physical_Country__c='UK',BillingCountry='UK',Partner_Reviews__c=NULL);
        insert flagTestAccount1;
        
        Account_Flag_Status_Controller cntrl = new  Account_Flag_Status_Controller( new ApexPages.StandardController(flagTestAccount));
        
        System.assertNotEquals(cntrl.AccountId, NULL);        
        System.assertEquals(cntrl.back().getURL(), '/' + cntrl.AccountId);
       
        
        Account_Flag_Status_Controller cntrl1= new  Account_Flag_Status_Controller( new ApexPages.StandardController(flagTestAccount));
        System.assertEquals(cntrl1.back().getURL(), '/' + cntrl1.AccountId);
    }

}

 

Navatar_DbSupNavatar_DbSup

Hi,

Try the below code as reference and made changes accordingly. I have removed all the custom field and condition to run the code at my end please make changes as per your requirement:

public with sharing class Account_Flag_Status_Controller {

   

    public Id AccountId{get;set;}

    public List<Flag_Reporter__c> flagReport{get;set;}

    public Account_Flag_Status_Controller(ApexPages.StandardController controller) {

        AccountId= ApexPages.currentPage().getParameters().get('id');

        flagReport = new List<Flag_Reporter__c>();

    }

   

    public class FlagColors{

        public String overallStatus{get;set;}

        public String leadFlag{get;set;}

        public String creditFlag{get;set;} 

        public String venueFlag{get;set;}

        public String companyFlag{get;set;}

        public String editorial{get;set;}

        public String websiteFlag{get;set;}

        public String msFlag{get;set;}

        public String pmFlag{get;set;}

        public String escalationFlag{get;set;}

        public String FlagComments{get;set;}

        public String OverallComments{get;set;}

    }

   

    public Pagereference back() {

        Pagereference contractPage = new Pagereference('/' + AccountId);

        return contractPage;

    }

   

    public FlagColors colorSetter{

    get{

   

        FlagColors flagColors = new FlagColors();

        try{

            flagReport = [Select id  from Flag_Reporter__c Where Account_Flag__c=:AccountId LIMIT 1];

           

        }

        catch(Exception ex)

        {

            flagColors.overallStatus = 'Green.png';

            flagColors.leadFlag = 'Green.png';

            flagColors.creditFlag= 'Green.png';

            flagColors.venueFlag= 'Green.png';

            flagColors.companyFlag= 'Green.png';

            flagColors.editorial= 'Green.png';

            flagColors.websiteFlag= 'Green.png';

            flagColors.msFlag= 'Green.png';

            flagColors.pmFlag= 'Green.png';

            flagColors.escalationFlag= 'Green.png';

           

            return flagColors;

           

        }

       

          return flagColors;       

       

    }

   

   

    }

    static testMethod void testWithFlag() {

   

        Account flagTestAccount = new Account(Name='Flag Test Account');

        insert flagTestAccount;

       

        Account flagTestAccount1 = new Account(Name='Flag Test Account');

        insert flagTestAccount1;

        FlagColors f=new FlagColors();

        Account_Flag_Status_Controller cntrl = new  Account_Flag_Status_Controller( new ApexPages.StandardController(flagTestAccount));

      

        cntrl.back();

      

    }

 

}

prazonprazon

Thanks Mr.Jain..

 

It worked I want to pass Account Id in the controller in the test class in order to run the query in the class and test those conditions. I was trying the following but it's not working. Please tell me what can be the correct syntax, way it can be done

 

 

 



 

prazonprazon

code

 

Test.setCurrentPage(Page.flagStatusPage);        

 

 Account_Flag_Status_Controller cntrl1= new  Account_Flag_Status_Controller( new ApexPages.StandardController(flagTestAccount1));        

 

System.assertNotEquals(cntrl.AccountId, flagTestAccount1.Id);        

System.assertEquals(cntrl1.back().getURL(), '/' + cntrl1.AccountId);