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:
- How to instantiate this class from a testing class?
- How to set the currentPage Id ?
- Should I use a stub class too?
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!