0

The test class below is covering the class successfully but I am getting difficulty to cover my wrapper list.

Coverage

Coverage Screenshot

I added data for lstPayslip in test class. I want to cover listWrapper. Getting trouble here.

my test class is as follows:

@isTest
public class DisplayPayslipControllerTest {

    //Global Variables
    private static Payslip__c objPayslip;
    private static List<Payslip__c> listPayslip;
    private static Employee__c objEmployee;
    private static Boolean Bool;

    //Data to test
    @testSetup
    public static void testData() {

        listPayslip=new List<Payslip__c>();
        objEmployee=new Employee__c(Name='TestOne',Password__c='Set@123',Mobile_Number__c='9876534563',
                                    Tech_Official_Email_ID__c='samruddhipode.techila@gmail.com');
        insert objEmployee;

        objPayslip=new Payslip__c(Total_Attendence__c=30,Last_Sent_Date1__c=system.now(),Sent_Date__c=system.now(),
                                  Other_Deduction__c=2000,ESIC_Monthly__c=2000,Techila_Variable__c=200,C_A__c=3000,
                                  Leave_Encashment__c=500,TDS_Monthly__c=6000,Advance_Monthly__c=6000,
                                  Opening_Balance__c=2,Leave_Availed__c=1,
                                  Techila_Basic__c=2000,PF_Employee_12_till_date__c=2000,PF_Employer_12_till_date__c=2000,
                                  Monthly_Fixed_HRA__c=5000,Food__c=1000,
                                  Fixed_Education_Allowance__c=1000,
                                  PT_Monthly__c=100,
                                  Techila_Medical_Allowance__c=3000,
                                  Monthly_PF__c=200,
                                  Techila_Year__c='2016',
                                  For_the_Month__c='JAN',Employee__c=objEmployee.id
                                // Id = ApexPages.currentPage().getParameters().get('id')
                                 );
      //  insert objPayslip;  
        system.debug('objPayslip------------->'+objPayslip);
        listPayslip.add(objPayslip);
    }

    public static testmethod void mthdDisplayPayslip() {

        testData();
        insert listPayslip;
        ApexPages.currentPage().getParameters().put('id', objPayslip.Id);

         ApexPages.StandardController sc = new ApexPages.StandardController(objPayslip); 

        //Instance of controller
           DisplayPayslipController objPaySend = new DisplayPayslipController(sc);        
           objPaySend.getrecords(); 
          // objPaySend.selectAll();          
           objPaySend.send();
           DisplayPayslipController.WrapperClass objWrapperClass=new DisplayPayslipController.WrapperClass(objPayslip,false);
    }


}
  • 1
    Please edit your post to include relevant controller code as text as well. – Adrian Larson Jan 13 '17 at 12:40
1

You need to set the either strSelected or strSelected1 to a non-blank, non-null value before you call your method:

objPaySend.strSelected = 'Hello World';
objPaySend.getRecords();

Make sure that the strSelected or strSelected1 variable matches the payslip record you created.

Side notes:

You can use String.isNotBlank(strSelected) instead of strSelected != null && strSelected != ''. It's a bit easier to read and quite a bit shorter, too.

You don't need to check if the list is empty before you iterate over an empty list. You can delete lines 90 and 94.

Action methods can use the void return type instead of using return null. More experienced developers tend to expect that a method might be capable of redirecting if a PageReference return type is used. This would also eliminate the need for line 96.

Change:

public PageReference getRecords() {

To:

public void getRecords() {
  • Thank you so much sfdcfox. It worked. Thank you for the guidance too since i am a beginner i need that. Now my wrapper list covered successfully but i am getting trouble to cover the send() method. It is the action for sending email to the checked records(checkbox). – p.samruddhi Jan 16 '17 at 5:35
  • @p.samruddhi I presume it'll be more of the same; you need to populate the list, then set selected to true for one or more wrapper items, then call the send method. – sfdcfox Jan 16 '17 at 5:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.