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
Varun TejaVarun Teja 

How to write test class for apex controller

Need test class for below code

public class AccountSubmitPageController {
    
    public Account acount{get; set;}
    public Contact contct{get; set;}
    public Opportunity oportunity{get; set;}
    public Case casse{get; set;}

    public List<Contact> contactList{get; set;}
    public List<Opportunity> OppoList{get; set;}
    
    public AccountSubmitPageController(ApexPages.standardController controller){  
        acount = new Account();
        contct = new Contact();
        oportunity= new Opportunity();
        casse=new Case();
        contactList=new List<Contact>();
        OppoList=new List<Opportunity>();
    }

    public PageReference save() {

        insert acount;
        PageReference bp = new PageReference('/apex/ContactSubmitPage');
        bp.setRedirect(false);
        return bp;
        
    }
    
    public PageReference addMoreContacts() {

        contct.AccountId=acount.Id;
        if (!contactList.contains(contct)) {
             contactList.add(contct);
        }
        contct=new Contact();
        PageReference pageref = new PageReference('/apex/ContactSubmitPage');
        pageref.setRedirect(false);
        return pageref;
    }
    
    public PageReference dontWantContact() {
        PageReference bp = new PageReference('/apex/OpportunitySubmitPage');
        bp.setRedirect(false);
        return bp;
    }
    public PageReference submitContact() {
        contct.AccountId=acount.Id;
        if (!contactList.contains(contct)) {
            contactList.add(contct);
        }
        if(contactList.size()>0){

            insert contactList;
        }
        
        PageReference pr = new PageReference('/apex/OpportunitySubmitPage');
        pr.setRedirect(false);
        return pr;
        
    }
    
    public PageReference addMoreOpportunities() {
        
        oportunity.AccountId=acount.Id;

        if (!OppoList.contains(oportunity)) {
            OppoList.add(oportunity);
        }
        oportunity=new Opportunity();
        PageReference pageref = new PageReference('/apex/OpportunitySubmitPage');
        pageref.setRedirect(false);
        return pageref;
    }
    
       public PageReference dontWantOpportunity() {
        PageReference bp = new PageReference('/apex/CaseSubmitPage');
        bp.setRedirect(false);
        return bp;
    }
    
    public PageReference submitOpportunity() {
        oportunity.AccountId=acount.Id;
        if (!OppoList.contains(oportunity)) {
            OppoList.add(oportunity);
        }
        if(OppoList.size()>0){

            insert OppoList;
        }
        PageReference pr = new PageReference('/apex/CaseSubmitPage');
        pr.setRedirect(false);
        return pr;
    }
    
    public PageReference caseConfirm() {
        casse.AccountId=acount.Id;
        insert casse;
        Case cs=[select Id,CaseNumber from Case where AccountId=:acount.Id];

        PageReference pr = new PageReference('/apex/ListAllSubmitPage?caseNumbr='+cs.CaseNumber);
        pr.setRedirect(false);
        return pr;
    }
    
        public PageReference done() {
        acount = new Account();
        PageReference pageref = new PageReference('/apex/AccountSubmitPage');
        pageref.setRedirect(false);
        return pageref;
    }
 }