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
Roelof WalRoelof Wal 

test custom class, where to start?

I have a custom class which needs testing but I have no clue how to and where to get started. 
Below is an example of the original. 
This code is used on a custom Apex page to generate some output.
public with sharing class getCustomvalues {

		private final Account account;
    	public List<String> myitems {get; private set;}
    	
    	public List<Account_items__c> result {get;set;}
    
    	public getCustomvalues() {
            Id id = ApexPages.currentPage().getParameters().get('id');
            account =  [SELECT Account.Name, items__c FROM Account WHERE Id = :id];
            myitems = new List<String>();
            if (account.items__c== null) {
			    /*
					code
				*/
            } else {
			    /*
					code
				*/
            }
        }

        public Account getAccount() {
        
    	    return account;
	    }

}

My questions:
  1. How to instantiate this class from a testing class?
  2. How to set the currentPage Id ?
    1. Should I use a stub class too?
Best Answer chosen by Roelof Wal
CharuDuttCharuDutt
Hii RoleOfWal
Try Below Test Class
@isTest
public class getCustomvaluesTest {
	@isTest
    public static void unitTest(){
        Account Acc= new Account();
        Acc.Name = 'Test';
        insert Acc;
        Account Acc2 = new Account();
        Acc2.Name = 'Account2';
        Acc2.ParentId = Acc.Id;
        Acc2.items__c = //Fill This
        Insert Acc2;
		ApexPages.currentPage().getParameters().put('id',Acc2.Id);
        getCustomvalues gcv = new getCustomvalues();
        gcv.getAccount();
    }
}
Please Mark It As Best Asnwer If It Helps
Thank You!

All Answers

CharuDuttCharuDutt
Hii RoleOfWal
Try Below Test Class
@isTest
public class getCustomvaluesTest {
	@isTest
    public static void unitTest(){
        Account Acc= new Account();
        Acc.Name = 'Test';
        insert Acc;
        Account Acc2 = new Account();
        Acc2.Name = 'Account2';
        Acc2.ParentId = Acc.Id;
        Acc2.items__c = //Fill This
        Insert Acc2;
		ApexPages.currentPage().getParameters().put('id',Acc2.Id);
        getCustomvalues gcv = new getCustomvalues();
        gcv.getAccount();
    }
}
Please Mark It As Best Asnwer If It Helps
Thank You!
This was selected as the best answer
Roelof WalRoelof Wal
You made my day !
Now I write the tests, this put me in the right direction.