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
Chaim Rosenfeld 8Chaim Rosenfeld 8 

test class for controller with multiple methods

Hello guys, can any one please help me creating test class which include multiple methods, 
my controller code is as 

public class addProposalCntrl {



   


    Public string leadID{get;set;}
    Public string testlpropID{get;set;}
    Public string testppropID{get;set;}
    Public string testspropID{get;set;}
    Public string testcommID{get;set;}
    Public string testresdID{get;set;}
    Public Lead lead {get;set;}
    
    Public string floorPOID{get;set;}
    Public string generalpccPOID{get;set;}
    Public string windowPOID{get;set;}

    
    Public Laborer_Mid_Construction_Proposal__c lprop {get;set;}
    Public Laborer_Mid_Construction_Proposal__c testlprop {get;set;}
    Public Laborer_Mid_Construction_Proposal__c lpropIns {get;set;}
    Public Steady_Maintenance_Proposal__c sprop {get;set;}
    Public Steady_Maintenance_Proposal__c testsprop {get;set;}
    Public Post_Construction_Cleanup_Proposal__c pprop {get;set;}
    Public Post_Construction_Cleanup_Proposal__c testpprop {get;set;}
    Public Steady_Maintenance_Commercial__c steadyComm{get;set;}
    Public Steady_Maintenance_Commercial__c teststeadyComm{get;set;}
    Public Steady_Maintenance_Residential__c steadyResd{get;set;}
    Public Steady_Maintenance_Residential__c teststeadyResd{get;set;}
    
    Public Floor_Cleaning_Project_Over_View__c  floorPO{get;set;}
    Public Floor_Cleaning_Project_Over_View__c  testfloorPO{get;set;}
    Public General_PCC_Project_Over_View__c generalpccPO{get;set;}
    Public General_PCC_Project_Over_View__c testgeneralpccPO{get;set;}
    Public Window_Cleaning_Project_Overview__c windowPO{get;set;}
    Public Window_Cleaning_Project_Overview__c testwindowPO{get;set;}







    


    public addProposalCntrl () {    
    
    testlpropID= 'a091g000004naaqAAA';
    testppropID = 'a0B1g0000033u90EAA';
    testspropID = 'a0A1g000000RlDZEA0';
    testcommID = 'a0C1g000000saTmEAI';
    testresdID = 'a0D1g000002274aEAA';
    floorPOID = 'a0b1g000001CBfXAAW';
    generalpccPOID = 'a0c1g000000UGEgAAO';
    windowPOID = 'a0a1g00000192O3AAI';
    
    
    testlprop = [SELECT Marketing_Material__c, Holiday_Coverage__c,Management_and_Supervision__c, Over_Time_Hours__c, Pricing__c , Payment_Terms__c,Statement_of_Work__c,Supplies_and_Equipment__c FROM Laborer_Mid_Construction_Proposal__c where ID =: testlpropID];
    testpprop = [SELECT Contract_Terms__c, Pricing_and_Agreement__c FROM  Post_Construction_Cleanup_Proposal__c where ID =: testppropID];
    testsprop = [SELECT Extraordinary_Maintenance_Requirements__c,Holiday_Coverage__c, Payment_Terms__c , Pricing__c, Sick_Pay__c, Supplies_and_Equipment__c  , Uniform__c , Marketing_Material__c FROM  Steady_Maintenance_Proposal__c where ID =: testspropID];
    teststeadyComm = [SELECT id, Scope_of_Work__c from Steady_Maintenance_Commercial__c  where id =: testcommID ];
    teststeadyResd = [SELECT id, Scope_of_Work__c from Steady_Maintenance_Residential__c where id =: testresdID ];
    testfloorPO = [select id, Project_Overview__c   from Floor_Cleaning_Project_Over_View__c  where id =: floorPOID ];
    testgeneralpccPO = [select id, Project_Overview__c  from General_PCC_Project_Over_View__c  where id =: generalpccPOID ];
    testwindowPO = [select id, Project_Overview__c  from Window_Cleaning_Project_Overview__c where id =: windowPOID  ];

    leadID = apexpages.currentpage().getparameters().get('id');
    lead = new Lead(ID = leadID);
    pprop = new Post_Construction_Cleanup_Proposal__c(Lead__c = LeadID);
    sprop  = new Steady_Maintenance_Proposal__c(Lead__c = LeadID);
    lprop = new Laborer_Mid_Construction_Proposal__c (Lead__c = LeadID );
    steadyComm = new Steady_Maintenance_Commercial__c (Lead__c = leadID);
    steadyResd = new Steady_Maintenance_Residential__c (Lead__c = leadID);  
    floorPO = new Floor_Cleaning_Project_Over_View__c (Lead__c = leadID);
    generalpccPO = new General_PCC_Project_Over_View__c (Lead__c = leadID);
    windowPO = new Window_Cleaning_Project_Overview__c (Lead__c = leadID);
    
    }
    
    

Public PageReference saveRecordlprop(){

upsert lead;
update testlprop ; 
lprop.Marketing_Material__c = testlprop.Marketing_Material__c;
lprop.Holiday_Coverage__c = testlprop.Holiday_Coverage__c;
lprop.Management_and_Supervision__c = testlprop.Management_and_Supervision__c ;
lprop.Over_Time_Hours__c = testlprop.Over_Time_Hours__c ;
lprop.Payment_Terms__c = testlprop.Payment_Terms__c ;
lprop.Pricing__c = testlprop.Pricing__c ;
lprop.Statement_of_Work__c = testlprop.Statement_of_Work__c  ;
lprop.Supplies_and_Equipment__c = testlprop.Supplies_and_Equipment__c ;


 insert lprop;
    
   
    
    PageReference p = new PageReference('/' + this.lprop.Id );
    return p;
}

Public PageReference saveRecordspropComm(){
    upsert lead;
    update testsprop;
    sprop.Marketing_Material__c = testsprop.Marketing_Material__c;
    sprop.Extraordinary_Maintenance_Requirements__c = testsprop.Extraordinary_Maintenance_Requirements__c;
    sprop.Holiday_Coverage__c = testsprop.Holiday_Coverage__c;
    sprop.Payment_Terms__c = testsprop.Payment_Terms__c;  
    sprop.Pricing__c = testsprop.Pricing__c;  
    sprop.Sick_Pay__c = testsprop.Sick_Pay__c;  
    sprop.Supplies_and_Equipment__c  = testsprop.Supplies_and_Equipment__c  ;  
    sprop.Uniform__c = testsprop.Uniform__c;  
    update teststeadyComm ;
    steadyComm.Scope_of_Work__c = teststeadyComm.Scope_of_Work__c ;
    
    
    upsert steadyComm;
    

    upsert sprop;
    PageReference p = new PageReference('/' + this.sprop.Id );
    return p;
}

Public PageReference saveRecordspropResd(){
    upsert lead;
    update testsprop;
    sprop.Marketing_Material__c= testsprop.Marketing_Material__c;
    sprop.Extraordinary_Maintenance_Requirements__c = testsprop.Extraordinary_Maintenance_Requirements__c;  
    sprop.Holiday_Coverage__c = testsprop.Holiday_Coverage__c;
    sprop.Payment_Terms__c = testsprop.Payment_Terms__c;  
    sprop.Pricing__c = testsprop.Pricing__c;  
    sprop.Sick_Pay__c = testsprop.Sick_Pay__c;  
    sprop.Supplies_and_Equipment__c  = testsprop.Supplies_and_Equipment__c  ;  
    sprop.Uniform__c = testsprop.Uniform__c; 
            update teststeadyResd;
    steadyResd.Scope_of_Work__c = teststeadyResd.Scope_of_Work__c ;
    upsert steadyResd;
    upsert sprop;   
    PageReference p = new PageReference('/' + this.sprop.Id );
    return p;
}
Public PageReference saveRecordpprop1(){
    lead.PCC_Proposal_Added__c  = true;
    upsert lead;
    update testpprop;
    update testfloorPO ;
    pprop.Contract_Terms__c = testpprop.Contract_Terms__c;
    pprop.Pricing_and_Agreement__c = testpprop.Pricing_and_Agreement__c;
    floorPO.Project_Overview__c = testfloorPO.Project_Overview__c;
    upsert floorPO; 
    upsert pprop;
    PageReference p = new PageReference('/' + this.pprop.Id );
    return p;
}
Public PageReference saveRecordpprop2(){
    lead.PCC_Proposal_Added__c  = true;
    upsert lead;
    update testpprop;
    update testgeneralpccPO;
    pprop.Contract_Terms__c = testpprop.Contract_Terms__c;
    pprop.Pricing_and_Agreement__c = testpprop.Pricing_and_Agreement__c;
    generalpccPO.Project_Overview__c = testgeneralpccPO.Project_Overview__c ;
    upsert generalpccPO;
    upsert pprop;   
    PageReference p = new PageReference('/' + this.pprop.Id );
    return p;
}
Public PageReference saveRecordpprop3(){
    lead.PCC_Proposal_Added__c  = true;
    upsert lead;
    update testpprop;
    update testwindowPO;
    pprop.Contract_Terms__c = testpprop.Contract_Terms__c;
    pprop.Pricing_and_Agreement__c = testpprop.Pricing_and_Agreement__c;
    windowPO.Project_Overview__c = testwindowPO.Project_Overview__c ;
    upsert windowPO;
    upsert pprop;   
    PageReference p = new PageReference('/' + this.pprop.Id );
    return p;
}
}
 
Chaim Rosenfeld 8Chaim Rosenfeld 8
i have tried this test class, it didnt work 

@isTest 
public class addProposalCntrlTest{

static testMethod void testMethod1() {

        
        Laborer_Mid_Construction_Proposal__c testLRecord = new Laborer_Mid_Construction_Proposal__c();
        Steady_Maintenance_Proposal__c testSRecod = new Steady_Maintenance_Proposal__c();
        Post_Construction_Cleanup_Proposal__c testPRecord = new Post_Construction_Cleanup_Proposal__c();
        Steady_Maintenance_Commercial__c tesrSCRecord = new Steady_Maintenance_Commercial__c();
        Steady_Maintenance_Residential__c testSRRecord = new Steady_Maintenance_Residential__c();
        Floor_Cleaning_Project_Over_View__c testFCPORecord = new Floor_Cleaning_Project_Over_View__c();
        General_PCC_Project_Over_View__c testGPCCRecord = new General_PCC_Project_Over_View__c();
        Window_Cleaning_Project_Overview__c testWCPORecord = new Window_Cleaning_Project_Overview__c();
        
        testLRecord.Name = 'test';
        testSRecod.Name = 'test';
        testPRecord.Name = 'test';
        tesrSCRecord.Name = 'test';
        testSRRecord.Name = 'test';
        testFCPORecord.Name = 'test';
        testGPCCRecord.Name = 'test';
        testWCPORecord.Name = 'test';

        

        insert testLRecord;
        insert testSRecod;
        insert testPRecord;
        insert tesrSCRecord;
        insert testSRRecord;
        insert testFCPORecord;
        insert testGPCCRecord;
        insert testWCPORecord;
        

        Test.setCurrentPage(Page.addProposal);
        System.currentPageReference().getParameters().put('id', testLRecord.Id);
        System.currentPageReference().getParameters().put('id', testSRecod.Id);
        System.currentPageReference().getParameters().put('id', testPRecord.Id);
        System.currentPageReference().getParameters().put('id', tesrSCRecord.Id);
        System.currentPageReference().getParameters().put('id', testSRRecord.Id);
        System.currentPageReference().getParameters().put('id', testFCPORecord.Id);
        System.currentPageReference().getParameters().put('id', testGPCCRecord.Id);
        System.currentPageReference().getParameters().put('id', testWCPORecord.Id);

        
        
           addProposalCntrl testIns = new addProposalCntrl();
           testIns.saveRecordlprop();
           testIns.saveRecordspropComm();
           testIns.saveRecordspropResd();
           testIns.saveRecordpprop1();
           testIns.saveRecordpprop2();
           testIns.saveRecordpprop3();
        
   }
      
 }